为什么 CredentialCache.DefaultCredential 包含域、用户名和密码的空字符串
有谁知道为什么 CredentialCache.DefaultCredential 会返回一个 ICredential 实例,其中包含域、用户名和密码的空字符串?我在 IIS 7.5 上运行 WCF 服务。它在一台服务器上工作正常,但在另一台服务器上却无法工作。我已经验证 IIS 应用程序已启用 Windows 身份验证...
以下是它的使用方式:
string url = string.Format("{0}/departments/finance/_vti_bin/listdata.svc", _IntranetAddress);
var financeDataContext = new FinanceDataContext(new Uri(url))
{
Credentials = CredentialCache.DefaultCredentials
};
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
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定它在你们的一台服务器上是如何工作的?我希望你已经读过这篇文章
http://msdn.microsoft.com/en-us /library/system.net.credentialcache.defaultcredentials.aspx
但它明确表示“DefaultCredentials 返回的 ICredentials 实例不能用于查看当前安全上下文的用户名、密码或域”。
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."
从 CredentialCache.DefaultCredential 返回的 NetworkCredential 只是一个占位符。如果您使用调试器查看它,您将看到它的类型为 SystemNetworkCredential。内部 API 检查此类型以确定是否应使用集成身份验证。还有其他方法可以获取当前用户名(例如 WindowsIdentity.GetCurrent())。
编辑:
要指定 WCF 操作的模拟,请将此属性添加到实现协定的方法中:
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: