According to MSDN, "When using impersonation, ASP.NET applications can optionally execute with the identity of the client on whose behalf they are operating.
The usual reason for doing this is to avoid dealing with authentication and authorization issues in the ASP.NET application code. Instead, you rely on Microsoft
Internet Information Services (IIS) to authenticate the user and either pass an authenticated token to the ASP.NET application or, if unable to authenticate the
user, pass an unauthenticated token. In either case, the ASP.NET application impersonates whichever token is received if impersonation is enabled. The ASP.NET
application, now impersonating the client, then relies on the settings in the NTFS directories and files to allow it to gain access, or not. Be sure to format
the server file space as NTFS, so that access permissions can be set.
Impersonation is disabled by default and allows the ASP.NET process to act as the authenticated user, or as an arbitrary specified user. Impersonation can be
specified in the web.config file as shown below:
Listing VIII
<identity impersonate="true"/> or <identityimpersonate="false"/>
It is also possible to use a particular identity for all authenticated requests. This is possible by specifying the following in the application’s web.config file:
<identity impersonate="true" username="username"password="password"/>
How Authentication and Authorization Works
The following section lists the sequence of events that take place in the authentication and authorization process when a new request arrives.
The IIS first checks the validity of the incoming request. If the authentication mode is anonymous (default) then the request is authenticated automatically. But if
this authentication mode is overridden in the web.config file settings, the IIS performs the specified authentication check first before the request is passed on
to ASP.NET.
Now ASP.NET checks whether Impersonation is enabled or not. If impersonation is enabled, ASP.NET executes with the identity of the entity on behalf of which it is
performing executing the task. If impersonation is not enabled, the application runs with the identity of the IIS local machine's identity and the privileges of the
ASP.NET user account. ASPNET or NETWORK SERVICE is the default ASP.NET unprivileged account on Windows XP and Windows Server 2003, respectively. Now, the identity
that has already been authenticated and verified is used to request resources from the operating system. Then ASP.NET performs an authorization check on the
requested resources and if the user is authorized, it returns the request through IIS.
Suggested Readings
http://aspnet.4guysfromrolla.com/articles/031204-1.aspx
http://www.c-sharpcorner.com/Code/2003/Sept/AuthenticationAndAuthorization.asp
http://www.aspfree.com/c/a/IIS/Authentication-and-Authorization/
Conclusion
Application security plays a major role in building robust applications. The application should be able to restrict or limit access to the resources based on the
user's credentials and even disallow access to resources to unauthorized users of the system. This article just gave a basic idea about ASP.NET's in-built
Authentication and Authorization support. Please post your comments and suggestions. Happy reading!