How to get username and password of windows authentication from code

5.9k views Asked by At

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?

2

There are 2 answers

0
Rahul Singh On

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.

0
EvoPdf On

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