【问题标题】:Windows credentials not passing through using Windows.Web.Http.HttpClient未使用 Windows.Web.Http.HttpClient 传递的 Windows 凭据
【发布时间】:2016-03-20 12:35:17
【问题描述】:

我的应用正在尝试向我们域上的服务发出请求,但它未能通过运行该应用的用户的 Windows 凭据,这导致每次服务调用都需要登录请求(在排...超烦人)

如果我将ServerCredential 设置为PasswordCredential(使用 HttpBaseProtocolFilter)并使用硬编码信息(资源、用户名、密码),那么一切正常,但这还不够,因为它需要能够通过使用该应用程序的任何用户的信誉。

例子:

var filter = new HttpBaseProtocolFilter
{
    ServerCredential = new PasswordCredential("ourServiceHost", "username", "password")
});

var client = new HttpClient(filter);

我在某处读到,不设置 ServerCredential 应该会导致它默认为当前用户的 Windows 凭据,但这似乎没有发生。

想法?

【问题讨论】:

  • 您找到解决此问题的方法了吗?我面临同样的情况,我得到了和你一样的行为。如果我只有 var filter = new HttpBaseProtocolFilter();系统提示我输入凭据并且呼叫成功。如果我有 var filter = new HttpBaseProtocolFilter { AllowUI = false };它失败并出现错误 401 - 未经授权。
  • 那是不久前的事了,我不记得曾经真正找到解决方案,对不起。这是一个我不再从事的工作的工具的副项目。
  • 没问题。感谢您回复我。如果我找到解决方案,我也会在这里发布。

标签: .net win-universal-app


【解决方案1】:

您需要在应用的Package.AppxManifest 中选择企业身份验证 功能。

为避免出现用户名和密码提示,请禁用 UI:

HttpBaseProtocolFilter filter = new BaseProtocolFilter();
filter.AllowUI = false;
HttpClient client = new HttpClient(filter);

【讨论】:

  • 我添加了它,但没有任何变化。系统仍然提示我输入用户名和密码。
  • 我如何得到不成功的响应
  • 澄清一下:我不再被提示,但现在来自服务器的响应是 401
  • 您确定您的服务器配置正确吗?您可以使用 PowerShell 对其进行测试:Invoke-WebRequest -Method GET -Uri "http://example.com" -UseDefaultCredentials
  • 是的,如果我在 powershell 中运行它,我会得到一个 OK 响应
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多