This project is read-only.

Use programmatic impersonation to impersonate based on business logic

J.D. Meier, Jason Taylor, Prashant Bansode, Carlos Farre, Madhu Sundararajan, Steve Gregersen.

Use programmatic impersonation to impersonate the original caller or the ASP.NET service account calling into your service. Programmatic impersonation allows you to impersonate on specific lines of code rather than the entire operation. This finer-grained approach to impersonation can reduce security risk, however be aware that it is easier to make a mistake during implementation that could leave your code impersonating at higher privilege in the event of an error. Use the using statement to revert impersonation automatically.

The following code snippet shows how to impersonate programmatically
public string GetData(int value)
 using (*ServiceSecurityContext*.Current.WindowsIdentity.*Impersonate*())
     // return the impersonated user (original users identity)
     return string.Format("Hi, {0}, you have entered: {1}",
          WindowsIdentity.GetCurrent().Name, value);

Last edited Apr 24, 2008 at 1:07 AM by prashantbansode, version 2


No comments yet.