This shows how to configure the windows (IIS) authentication and impersonation in web.config or machine.config file. Configure authentication on an individual application basis in each applications’ web.config file. Note that authentication changes in machine.config are not required, since it reflects for all the web applications running on the server.
• #1
<authentication mode=”Windows”/ >
<identity impersonate=”true”/ > <!—this enables the impersonation
The above line makes the ASP.NET application code impersonates the IIS-authenticated caller. By default, impersonation is disabled.
• #2
<authentication mode=”Windows”/ >
<identity impersonate=”true” username=”Ibee\UserID” password=”UserID@123”/ >
This enables the entire application to run as “Ibee\UserID”, regardless of the identity of the request, as long as the password is correct.
Please note that UserName and Password are stored in a clear text in web.config file. Even though IIS will not transmit the web.config in response to a request, it can be read by other means. This approach is not recommendable.
To increase the security, the identity section can be encrypted and stored in the windows registry.
• #3
Username = “registry:HKLM\Software\ASPNetIdentity, Name”
Password = “registry:HKLM\Software\ASPNetIdentity, Password”
Criteria: Comma is required and the credentials must be stored in HKLM hive. The credentials must be in REG_BINARY Format. To do this, you can use the “Aspnet_setreg” executable available (can be downloaded), to accomplish the encryption, this executable uses the CryptProtectData windows API Function.
How to read the identity value programmatically?
Dim strUserName as string = System.Security.Principal.WindowsIdentity.GetCurrent ().Name
Configurable Setting
• Windows ACLs
Configure Windows Access Control Lists on resources accessed by your applications (Files, Folder and so on) against the original caller.
• URL Authorization
Configure URL Authorization in web.config file as mentioned beneath
<authorization>
<deny user=”Ibee\UserID”/ >
<allow roles=”Ibee\WindowsUserGroup”/ >
</authorization>
UserName follows the format DomainName\UserName.
Roles map the roles with windows-group
• Enterprise Level (COM+) Roles
Configure roles with the Component services administration tool or script.
Programmatic or Derivate Setting
• PrincipalPermission Demands
PrincipalPermission objPermChk = new PrincipalPermission (null, @“DomainName\WindowsGroup”);
• Explicit Role Check
Explicit role checking in .NET can be performed by using IPrincipal interface.
(e.g.) IPrincipal.IsInRole (@”Domain\WindowsGroup”);
• Enterprise Level (COM+) Roles
Explicit role checking in COM+ can be performed through the code using the ContextUtil class.
(e.g.) ContextUtil.IsCallerInRole (“RoleName”); RoleName can be manager.
Usage Scenario:
• Users have windows accounts that can be authenticated by the server.
• It requires minimal coding.