Sunday, April 11, 2010

Impersonation solves Access Denied Problem in asp.net

Add the following code in you code behind file where you need this.

WindowsIdentity currentUserIdentity = (WindowsIdentity)User.Identity;

WindowsImpersonationContext impersonationContext = currentUserIdentity.Impersonate();

try{

// do Something that requires saving, creating, or deleting files in the server.

}

catch(Exception ex){

if (impersonationContext != null)

{

impersonationContext.Undo();

}

}

No comments:

Post a Comment