Frequently Asked Interview Questions

How can you implement the impersonation in Asp.Net

We can impersonate a user on a thread in ASP.NET, you can use the following methods.
  1. Impersonate the IIS Authenticated Account or User

    Include an <identity> tag in the Web.config file of this application and set the impersonate attribute to true.
    For example:
    <identity impersonate="true" />
  2. Impersonate a Specific User for All the Requests of an ASP.NET Application.

    Specify the userName and password attributes in the <identity> tag of the Web.config file for that application.
    For example:
    <identity impersonate="true" userName="accountname" password="password" />
  3. Impersonate the Authenticating User in Code

    To impersonate the authenticating user (User.Identity) only when you run a particular section of code, you can use the code to follow. This method requires that the authenticating user identity is of type WindowsIdentity

    System.Security.Principal.WindowsImpersonationContext impersonationContext;
    impersonationContext =
    ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

    //Insert your code that runs under the security context of the authenticating user here.

    impersonationContext.Undo();

Most Visited Pages

Home | Site Index | Contact Us