Tuesday, February 3, 2009

Enabling Windows Authentication



This blog post summarizes - Enabling Windows Authentication within an Intranet ASP.NET Web application.




Though it is simple, best to document it here.


·          “Integrated Windows Authentication” (formerly called NTLM authentication) enabled within IIS.

·          In Web.config - <authentication> section which sets the mode to “Windows”. 

·          In Web.config - <authorization> section that denies access to “anonymous” users visiting the site.




        <authentication mode="Windows" />


             <deny users="?"/>






Obtaining the Logged-in Username:


In Page:


Dim username As String
username = User.Identity.Name 


In C# class:


Dim User As System.Security.Principal.IPrincipal
User = System.Web.HttpContext.Current.User


Dim username As String
username = User.Identity.Name



Looking up Role/Group information for a User


If User.IsInRole("DOMAIN\managers") Then
     Label1.Text = User.Identity.Name & " is a manager"
     Label1.Text = User.Identity.Name & " is not a manager"
End If



Hope this helps.


Arun Manglick


No comments:

Post a Comment