C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Training   ASP.NET Web Hosting    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

Play Silverlight Games or Submit your Silverlight applications and earn 90% AdSense revenue.

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Resources » Articles » ASP.NET/Web Applications »

Enabling Windows Authentication within an Intranet ASP.NET Web application


Posted Date: 13 May 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: MuthuKumarMember Level: Silver    
Rating: Points: 0



The status of this resource is Rejected.

Reason: Content originally appeared on Scott Gu's weblog over here: http://weblogs.asp.net/scottgu/archive/2006/07/12/Recipe_3A00_-Enabling-Windows-Authentication-within-an-Intranet-ASP.NET-Web-application.aspx






Responses

Author: saravanan    14 May 2008Member Level: Silver   Points : 2
Enabling Windows Authentication within an Intranet ASP.NET Web application
Problem:
You are building an Intranet web application for your organization, and you want to authenticate the users visiting your site. Specifically, you want to ensure that they are logged in using a valid Windows account on the network, and you want to be able to retrieve each incoming user's Windows account name and Windows group membership within your application code on the server.
Discussion:
Authentication is the process of identifying and validating the identity of a client accessing an application. Put more simply -- it is the process of identifying “who” the end-user is when they visit a website.
Authentication is typically used in combination with Authorization -- which is the process of figuring out whether the authenticated user has permissions to access a particular page/resource or to perform some action. For example, when an end-user in a browser tries to access a page, ASP.NET might authenticate the user as “Scott”, and would then run through the configured authorization rules for the requested page to figure out whether “Scott” has permission to access it.
ASP.NET supports multiple ways to authenticate browser users visiting a web application, and implements a flexible set of ways to authorize which permissions they have within the application.



Author: saravanan    14 May 2008Member Level: Silver   Points : 2













Author: saravanan    14 May 2008Member Level: Silver   Points : 2
You should also then add an section to the same web.config file that denies access to “anonymous” users visiting the site. This will force ASP.NET to always authenticate the incoming browser user using Windows Authentication – and ensure that from within code on the server you can always access the username and Windows group membership of the incoming user.
The below web.config file demonstrates how to configure both steps described above:













Author: saravanan    14 May 2008Member Level: Silver   Points : 2
Dim User As System.Security.Principal.IPrincipal
User = System.Web.HttpContext.Current.User
Dim username As String
username = User.Identity.Name
The code above obtains the User IPrincipal object for the current




Author: saravanan    14 May 2008Member Level: Silver   Points : 2
Note that the directive within the section above is what tells ASP.NET to deny access to the application to all “anonymous” users to the site (the “?” character means anonymous user). This forces Windows to authenticate the user, and ensures that the username is always available from code on the server.
Obtaining the Logged-in Username via Code
Once you follow the above configuration steps, you can easily access the logged-in username and role/group mappings for the authenticated user within ASP.NET. For example, you could use the code-snippet below within an ASP.NET page to easily obtain the username of the visiting user:
Dim username As String
username = User.Identity.Name
The code-snippet above works because there is a “User” property built-in to all ASP.NET pages and user-controls. If you want to gain access to this user data from within a regular class or business object (which doesn’t have this property provided), you can write code like below to achieve the same result:
Dim User As System.Security.Principal.IPrincipal
User = System.Web.HttpContext.Current.User
Dim username As String
username = User.Identity.Name
The code above obtains the User IPrincipal object for the current




Author: saravanan    14 May 2008Member Level: Silver   Points : 2
You should then add a web.config file to the root directory of your ASP.NET application that contains an section which sets the mode to “Windows”.
You should also then add an section to the same web.config file that denies access to “anonymous” users visiting the site. This will force ASP.NET to always authenticate the incoming browser user using Windows Authentication – and ensure that from within code on the server you can always access the username and Windows group membership of the incoming user.
The below web.config file demonstrates how to configure both steps described above:










Note that the directive within the section above is what tells ASP.NET to deny access to the application to all “anonymous” users to the site (the “?” character means anonymous user). This forces Windows to authenticate the user, and ensures that the username is always available from code on the server.
Obtaining the Logged-in Username via Code
Once you follow the above configuration steps, you can easily access the logged-in username and role/group mappings for the authenticated user within ASP.NET. For example, you could use the code-snippet below within an ASP.NET page to easily obtain the username of the visiting user:
Dim username As String
username = User.Identity.Name
The code-snippet above works because there is a “User” property built-in to all ASP.NET pages and user-controls. If you want to gain access to this user data from within a regular class or business object (which doesn’t have this property provided), you can write code like below to achieve the same result:
Dim User As System.Security.Principal.IPrincipal
User = System.Web.HttpContext.Current.User
Dim username As String
username = User.Identity.Name
The code above obtains the User IPrincipal object for the current



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Google Search Macro
Previous Resource: PagedDataSource Class For Paging
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use