Search code examples
c#.netasp.netimpersonationdelegation

Need to Impersonate user forAccessing Network resource, Asp.Net Account


I need to access a network resource on which only a given Domain Account has access. I am using the LogonUser call, but get a "User does not have required priviliege" exception, as the web application is running with the asp.net account and it does not have adequate permissions to make this call.

Is there a way to get around it? Changing the identity or permissions of the ASP.Net account is not an option as this is a production machine with many projects running. Is there a better way to achieve this?

Using Asp.Net 2.0, Forms Authentication.

Kind Regards.


Solution

  • Just calling LogonUser is not enough. You need to impersonate that user. You can impersonate for just the access to the network resource.

    Sample code can be found on MSDN.