How to access Windows user information in VB.NET

When your Web project is based on Windows authentication it does not require a login page. When end user requests a Web page that requires authentication, his browser transmits the credential to IIS and your application than retrieves information from the User property of the web page. You can use the next subroutine to display the currently authenticated user:

 

If Request.IsAuthenticated Then

‘ Display generic identity information.

lblInfoText.Text = “<b>Name: </b>” + User.Identity.Name

lblInfoText.Text += “<br><b>Authenticated With: </b>”

lblInfoText.Text += User.Identity.AuthenticationType

End If

 

Note: In case of Windows authentication the user name is always in the form DomainName\UserName or ComputerName\UserName and the next picture shows the result:

 

Displaying user information in VB.NET

Displaying user information in VB.NET