Friday 18 January 2013

Implement Impersonation in ASP.NET

Introduction

One of our websites uses Impersonation and a specific user account with special permissions to access certain system resources. The first step in enabling impersonation is setting up the correct attributes in the web.config file:

<system.web>
<identity impersonate="true" password="xxxxxx" userName="xxxxxxx" />   

By using the attribute impersonate="true", you are telling IIS that this website will be impersonating the configured user account.
Configure the website to use a specific user account

The next step is you need to go to IIS Manager and configure the user account you want to impersonate by this website.
Steps

Open IIS Manager.
Expand computer name.
Expand websites.
Click on the specific website for which you want to use impersonation.
On the right panel, under the heading "IIS", double click "Authentication".
Right click on "ASP.NET Impersonation" and select "Edit".
Choose "Specific User".
Click the SET button to provide the specific user name and password.
Press OK at the popup dialog to complete this step on enabling impersonation for website in IIS 7.0.

How to choose process identity for Application Pool in IIS 7.0

To set the correct user identity for the application pool, follow the steps below:

Open IIS Manager.
Click on "Application Pools" under the computer name.
On the right panel, right click on the application pool name (your website’s relevant application pool).
Select "Advanced properties".
Select "Identity" under "Process Model".
Click on the button to set the user account.
Select "Custom account".
Click on the button to specify the user account and password.
Press "OK".

Recycle the app pool by right clicking on the application pool name and selecting "Recycle" on the right click context menu to ensure all configuration changes have taken place.

You are all set to use your application with the impersonated user account.
Source:The Code Project Open License (CPOL)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.