Why does CredentialCache.DefaultCredential contain empty strings for domain, username, and password

StackOverflow https://stackoverflow.com/questions/7628504

  •  06-02-2021
  •  | 
  •  

Question

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

Here is how it's being used:

string url = string.Format("{0}/departments/finance/_vti_bin/listdata.svc", _IntranetAddress);
var financeDataContext = new FinanceDataContext(new Uri(url))
{
    Credentials = CredentialCache.DefaultCredentials
};
Était-ce utile?

La solution

The NetworkCredential returned from CredentialCache.DefaultCredential is just a placeholder. If you look at it using the Debugger, you'll see that it's of type SystemNetworkCredential. Internal API check for this type to see if integrated authentication should be used or not. There are other ways to get the current username (like WindowsIdentity.GetCurrent()).

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

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

Autres conseils

I am not sure how it is working in 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 user name, password, or domain of the current security context."

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top