【问题标题】:HttpListener and IntegratedWindowsAuthentication across networkHttpListener 和 IntegratedWindowsAuthentication 跨网络
【发布时间】: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


    【解决方案1】:

    恐怕为时已晚,但根据您的错误描述,这可能是(是)Kerberos 身份验证的问题。

    更具体地说,它是缺少 SPN 记录或请求标头不匹配。检查 Fiddler 中实际发送的内容并验证 SPN 是否匹配记录。我也怀疑你前缀中的指定端口。如果您的 url 中有非标准端口,则经常会发生此错误。

    【讨论】:

    • 现在已经很晚了,我将整个东西移植到 IIS,因为这是我可以让它真正正确验证的唯一方法。
    猜你喜欢
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 2010-09-30
    • 2023-04-08
    • 1970-01-01
    • 2020-06-12
    相关资源
    最近更新 更多