Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there not a User object? 1

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
I'm looking for a way to get the user login to my site. Using W2k security. I'm now looking at server variables, but I want to do this in .net.

I know it's there somewhere, but I can't seem to find any security class. namespace???

(.NET newbe)
 
This will populate the indicated textboxes with all of the authentication data.

void Page_Load(Object sender, EventArgs e)
{
IIdentity id = HttpContext.Current.User.Identity;
if(null != id)
{
contextName.Text = id.Name;
contextIsAuth.Text = id.IsAuthenticated.ToString();
contextAuthType.Text = id.AuthenticationType;
}
id = Thread.CurrentPrincipal.Identity;
if(null != id)
{
threadName.Text = id.Name;
threadIsAuthenticated.Text = id.IsAuthenticated.ToString();
threadAuthenticationType.Text = id.AuthenticationType;
}
id = WindowsIdentity.GetCurrent();
windowsName.Text = id.Name;
windowsIsAuth.Text = id.IsAuthenticated.ToString();
windowsAuthType.Text = id.AuthenticationType;
}
 
Thanks, but what does it look like in VB???

I can't seem to get it all to work. it's picky
 
For anyone who is interested:

Imports System
Imports System.Security.Principal
Imports System.Threading

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents contextName As System.Web.UI.WebControls.TextBox
Protected WithEvents contextIsAuth As System.Web.UI.WebControls.TextBox
Protected WithEvents contextAuthType As System.Web.UI.WebControls.TextBox
Protected WithEvents threadName As System.Web.UI.WebControls.TextBox
Protected WithEvents threadIsAuthenticated As System.Web.UI.WebControls.TextBox
Protected WithEvents threadAuthenticationType As System.Web.UI.WebControls.TextBox
Protected WithEvents windowsName As System.Web.UI.WebControls.TextBox
Protected WithEvents windowsIsAuth As System.Web.UI.WebControls.TextBox
Protected WithEvents windowsAuthType As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As IIdentity = HttpContext.Current.User.Identity
If id Is Nothing Then
contextName.Text = id.Name
contextIsAuth.Text = id.IsAuthenticated.ToString()
contextAuthType.Text = id.AuthenticationType
End If
id = Thread.CurrentPrincipal.Identity
If id Is Nothing Then
threadName.Text = id.Name
threadIsAuthenticated.Text = id.IsAuthenticated.ToString()
threadAuthenticationType.Text = id.AuthenticationType
End If
id = WindowsIdentity.GetCurrent()
windowsName.Text = id.Name
windowsIsAuth.Text = id.IsAuthenticated.ToString()
windowsAuthType.Text = id.AuthenticationType

End Sub

End Class
 
This will tell you who is currently logged into the machine

Response.Write(&quot;<br>windowsName = &quot; & System.Security.Principal.WindowsIdentity.GetCurrent.Name)

Response.Write(&quot;<br>windowsIsAuth = &quot; & System.Security.Principal.WindowsIdentity.GetCurrent.IsAuthenticated.ToString())

Response.Write(&quot;<br>windowsAuthType = &quot; & System.Security.Principal.WindowsIdentity.GetCurrent.AuthenticationType)
 
When I wrote that last post &quot;This will tell you who is currently logged into the machine&quot;, your big post &quot;for anyone who is interested&quot; had not yet appeared on this thread;
So my post just ended up repeating what you had already posted, I think the two posts must have been made almost simultaneously.
thank you

Nelson
 
Only gos to prove that great minds think alike.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top