Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I impersonate logged on user and get access to unc folders?
    primarykey
    data
    text
    <p>I'm having trouble impersonating logged on user and then access unc files. I have tried using this sample code:</p> <pre><code>using System.Security.Principal; ... // Obtain the authenticated user's Identity WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity; WindowsImpersonationContext ctx = null; try { // Start impersonating ctx = winId.Impersonate(); // Now impersonating // Access resources using the identity of the authenticated user } // Prevent exceptions from propagating catch{} finally { // Revert impersonation if (ctx != null) ctx.Undo(); } // Back to running under the default ASP.NET process identity </code></pre> <p>If I try to access a file locally where the comment says <em>Access resources using the identity of the authenticated user</em> it works exactly as it should. If I however try to do the same thing with a file on a file server somewhere using UNC like \\ServerName\Share\FileName.txt it doesn't matter that the impersonated account has enough rights. The application throws an exception saying that the ASP.NET account does not have enough rights.</p> <p>I have also tried to use unmanaged code to perform the impersonation and then it works! Local file or UNC, doesn't matter, works like a charm!</p> <p>The problem is that you have to provide password and since it is the logged on users rights I want to check I can't provide that.</p> <p>Does anyone know why the application behaves like this? Is it some configuration setting I need to set? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload