How to get user account info in code with Windows Authentication?
If WebApp is configured as Windows Au开发者_如何学运维thentication, how to get the user credential in code? How to create NetworkCredential using this exsiting user credential?
System.Net.CredentialCache.DefaultCredentials;
The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.
DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.
Example:
System.Net.WebProxy proxyObject = new System.Net.WebProxy();
proxyObject.Credentials = System.Net.CredentialCache.DefaultCredentials;
精彩评论