c# - How can I impersonate logged on user and get access to unc folders? -



c# - How can I impersonate logged on user and get access to unc folders? -

i'm having problem impersonating logged on user , access unc files. have tried using sample code:

using system.security.principal; ... // obtain authenticated user's identity windowsidentity winid = (windowsidentity)httpcontext.current.user.identity; windowsimpersonationcontext ctx = null; seek { // start impersonating ctx = winid.impersonate(); // impersonating // access resources using identity of authenticated user } // prevent exceptions propagating catch{} { // revert impersonation if (ctx != null) ctx.undo(); } // running under default asp.net process identity

if seek access file locally comment says access resources using identity of authenticated user works should. if seek same thing file on file server somewhere using unc \\servername\share\filename.txt doesn't matter impersonated business relationship has plenty rights. application throws exception saying asp.net business relationship not have plenty rights.

i have tried utilize unmanaged code perform impersonation , works! local file or unc, doesn't matter, works charm!

the problem have provide password , since logged on users rights want check can't provide that.

does know why application behaves this? configuration setting need set?

web application runs specific identity, identity based on user business relationship on local machine or domain.

the application uses identity when accesses resources on disk or services.

if business relationship not have rights resource, web application not able utilize resource.

impersonation web application assumes different identity default

impersonation can configured used web application on startup, adding tag web.config file. impersonation can implemented dynamically in code, can turned on , off needed.

from asp.net identity , impersonation

so check web.config , iis configuration , ensure you're impersonating right user.

c# impersonation unc

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -