为什么CredentialCache.DefaultCredential包含域,用户名和密码的空字符串 [英] Why does CredentialCache.DefaultCredential contain empty strings for domain, username, and password

查看:243
本文介绍了为什么CredentialCache.DefaultCredential包含域,用户名和密码的空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人想知道为什么CredentialCache.DefaultCredential会返回一个ICredential实例,其中包含域名,用户名和密码的空字符串?我在IIS 7.5上运行WCF服务。它在一台服务器上工作正常,但从不在另一台服我已经验证IIS应用程序已启用Windows身份验证....

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....

以下是它的使用方式:

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


推荐答案

从CredentialCache.DefaultCredential返回的NetworkCredential只是一个占位符。如果使用调试器查看它,您将看到它的类型为SystemNetworkCredential。此类型的内部API检查以查看是否应使用集成身份验证。还有其他方法可以获取当前用户名(如WindowsIdentity.GetCurrent())。

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()).

编辑:
要为WCF操作指定模拟,请添加此属性实现合同的方法:

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
}

这篇关于为什么CredentialCache.DefaultCredential包含域,用户名和密码的空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆