ASP.NET Impersonation
Literally, impersonation means the act of pretending to be another person. In technical terms, it is an ASP.NET security feature that provides the ability to control the identity under which application code is run. Impersonation occurs when ASP.NET runs code in the context of an authenticated and authorized client. IIS provides anonymous access to resources by using an IUSR account. After the request is passed along to ASP.NET, the application code is run by using the application pool identity.
Impersonation can be enabled both through IIS and ASP.NET code if the application uses anonymous authentication, and if one of the following conditions is true:
- If IMPERSONATION is disabled, the application pool identity is used to run the application code.
- If IMPERSONATION is enabled, "NT AUTHORITY\IUSR" is used to run the application code.
When impersonation is enabled through IIS, it adds the following tag in the Web.config file of the application to impersonate the IIS Authenticated Account or User:
<identity impersonate="true" />
To impersonate a specific user for all requests on all pages of an ASP.NET application, you can specify the user name and password attributes in the <identity> tag of the Web.config file for that application.
<identity impersonate="true" userName="accountname" password="password" />
Note: the account specified in <identity> has to belong to IIS_IUSRS local group to be able to run web app on local machine.