Why does CredentialCache.DefaultCredential contain blank lines for domain, username and password

Does anyone have any ideas as to why CredentialCache.DefaultCredential will return an ICredential instance with empty strings for domain, username and password? I am running the WCF service in IIS 7.5. It works fine on one server, but never works on another. I verified that the IIS application has Windows authentication ....

Here's how it is used:

string url = string.Format("{0}/departments/finance/_vti_bin/listdata.svc", _IntranetAddress); var financeDataContext = new FinanceDataContext(new Uri(url)) { Credentials = CredentialCache.DefaultCredentials }; 
+2
source share
2 answers

The NetworkCredential returned from CredentialCache.DefaultCredential is simply a placeholder. If you look at it using Debugger, you will see that it is a type of SystemNetworkCredential. The internal API checks this type to see whether to use integrated authentication or not. There are other ways to get the current username (for example, WindowsIdentity.GetCurrent ()).

EDIT: To specify an impersonation for a WCF operation, add this attribute to the method that implements the contract:

 [OperationBehavior(Impersonation = ImpersonationOption.Required)] public void SomeMethod() { // do something here } 
+1
source

I'm not sure how it works on one of your servers? I hope you already read this http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials.aspx but it clearly says: "The ICredentials instance returned by DefaultCredentials cannot be used to view the username , password, or domain of the current security context. "

+2
source

All Articles