asp.net - C# ASP .NET; Get the NetworkCredential Object for the logged in user? -
i have implement following scenario: asp .net webapp 1. user logs in 2. logged in user's credentials have download files sharepoint site;
environment: - right web.config set impersonation on, , windows auth. on, have work basic authentication - use system.net.webclient download sharepoint files using sharepoint site's web services, , webclient needs credential object, that's why need networkcredential object.
p.s: credentialcache.defaultcredentials , credentialcache.defaultnetworkcredentials returns credential empty username , pw, cannot use acccessing sharpeoint site. not suitable system.security.principal.windowsidentity.getcurrent() or system.web.httpcontext.current.user.identity, because can username way, , instantiating networkcredential need uname , pw.
fyi, think i've managed solve issue; i'm using impersonation context, , use credentialcache.defaultnetworkcredentials
, , set webclient
's usedefaultcredentials
true, , seems working far. so:
windowsidentity identity = system.security.principal.windowsidentity.getcurrent(); using (identity.impersonate()) { webclient.credentials = credentialcache.defaultnetworkcredentials; webclient.usedefaultcredentials = true; }
this worked me.
Comments
Post a Comment