简体   繁体   中英

How to get username and password of windows authentication from code

I need to pass WINDOWS AUTHENTICATION details of logged in user to the pdf converter to make it work. I've tried this

PdfConverter.AuthenticationOptions.Username = CredentialCache.DefaultNetworkCredentials.UserName;
PdfConverter.AuthenticationOptions.Password = CredentialCache.DefaultNetworkCredentials.Password;

But this doesn't help. Converter is working locally, but returning 404 errors in the server where windows authentication is enabled.

How can I get credentials with the code?

Try this:- (You can use WindowsIdentity )

WindowsIdentity id = HttpContext.Current.Request.LogonUserIdentity;
String UserName = id.Name;

I don't think we can retrieve password since passwords are not stored in Windows.

You should upgrade to the latest version which uses the credentials of the current Windows to access the web page from IIS. This can be disabled if you want with HtmlToPdfConverter.AuthenticationOptions.UseDefaultCredentials property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM