【发布时间】:2018-09-28 20:07:56
【问题描述】:
我有一个用autorest 生成的Microsoft.Rest.ServiceClient。我想访问一个使用 Windows 身份验证和基本身份验证保护的 REST API。
目标是使用 Windows 身份验证。我尝试如下:
var handler = new HttpClientHandler
{
UseDefaultCredentials = true,
};
this.InitializeHttpClient(handler);
这不起作用,我明白了:
System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
---> System.ComponentModel.Win32Exception: The target principal name is incorrect
当我使用基本身份验证时,它可以工作。
this.Credentials = new BasicAuthenticationCredentials
{
UserName = Configuration.User,
Password = Configuration.Password
};
ServiceClient 的设置是在
MyClient : Microsoft.Rest.ServiceClient
我需要向客户端添加什么才能使 Windows 身份验证正常工作?
已编辑:
看起来问题出在服务器端。 IIS 中的设置。
客户端会按预期工作。
【问题讨论】:
-
进程是在您的 Windows 主体还是其他帐户下运行?
-
我都试过了,但正如问题中提到的,客户炒锅是正确的。
标签: c# .net windows-authentication autorest