绑定到FQDN或IP地址时,Windows身份验证在自托管的Katana中不起作用

时间:2018-09-21 14:22:15

标签: c# windows-authentication katana self-host-webapi

我试图运行一个使用Windows身份验证并绑定到FQDN的Katana自托管实例。

以下代码仅在url引用localhost或计算机名称时才有效。但是,当我尝试使用FQDN或IP地址时,Chrome会不断循环提示输入凭据。此时输入我的凭据也不起作用。

Katana启动的每个示例都使用本地主机,如下所示: Enabling Windows Authentication in Katana

我有一个foo.bar的主机项,引用了我的计算机的本地IP地址,并且正在从管理命令提示符处执行。我曾尝试使用netsh来添加一个urlacl条目,但是没有运气,但是由于我以Admin身份执行,因此我认为这不是必需的。

我也尝试了IntegratedWindowsAuthentication模式,该模式具有相同的结果。

如何使用Windows身份验证为http://foo.bar提供Katana答复请求?

有效的网址:

  • http:// *:端口
  • http://localhost端口
  • http:// 计算机名称
  • http:// 计算机名称端口

没有以下网址:

class Program {
    static void Main(string[] args) {
        try {
            var url = args.Length == 1 ? args[0] : "http://localhost:9001";
            using (var webapi = WebApp.Start<Program>(url)) {
                Console.WriteLine("running on " + url);
                Console.ReadKey();
            }
        }
        catch (Exception ex) {
            Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
        }
    }

    public void Configuration(IAppBuilder app) {
        var listener = (HttpListener)app.Properties["System.Net.HttpListener"];
        //listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
        listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm;

        app.Run(ctx => {
            Console.WriteLine(ctx.Request.Path);
            ctx.Response.ContentType = "text/plain";
            return ctx.Response.WriteAsync("hi " + DateTime.UtcNow.ToString("O"));
        });
    }
}

0 个答案:

没有答案
相关问题