【发布时间】:2016-12-29 14:52:18
【问题描述】:
我使用 HttpListener 创建了一个 ClickOnce 服务。我需要验证用户的连接:
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:80/ClickOnce/");
listener.AuthenticationSChemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
while (true)
{
var context = listener.GetContext();
var id = context.User.Identity as WindowsIdentity;
if (id != null)
{
using (var impersonated = id.Impersonate())
{
...
}
}
}
只要该服务与 Http 客户端位于同一台机器上,它就可以正常工作。但是如果我尝试从另一台机器连接到该服务,它会拒绝进行身份验证。
如果我通过 Internet Explorer 连接,它会提示输入用户名/密码,尝试连接,然后返回提示。
如果我通过 Chrome 连接,它只会显示“此网页不可用 ERR_INVALID_AUTH_CREDENTIALS”。
如果我运行 VSTOInstaller.exe,它会给出以下错误:
System.Deployment.Application.DeploymentDownloadException: Downloading http://.../OutlookAddin.vsto did not succeed.
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
System.ComponentModel.Win32Exception: The target principal name is incorrect
at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode)
...
如果我配置匿名身份验证,它允许请求通过,但我无法对用户进行身份验证。
HttpListener 可以通过网络进行身份验证吗?或者是否有另一种替代 HttpListener 的方法可以正确支持这种情况?
【问题讨论】:
标签: windows-authentication httplistener