简体   繁体   English

自托管的OWIN .NET 4.5 Web API 2不适用于Windows身份验证和https

[英]Self-hosted OWIN .NET 4.5 Web API 2 does not work with Windows authentication and https

I am trying to get Web API 2 to work with Windows authentication and SSL. 我正在尝试使Web API 2与Windows身份验证和SSL一起使用。 It looks like it can work with either one or the other, but when I enable both Windows authentication and SSL, I keep getting 401 responses from the server. 看起来它可以与任何一个一起使用,但是当我同时启用Windows身份验证和SSL时,我不断从服务器获得401响应。

This is how we enable Windows authentication: 这是我们启用Windows身份验证的方式:

HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;

When running with just HTTP (no HTTPS), Windows authentication seems to work. 当仅使用HTTP(无HTTPS)运行时,Windows身份验证似乎可以工作。 I see 401 responses followed by a 200 response. 我看到401响应,然后是200响应。

I am also trying to get it to work with HTTPS on my local machine. 我还试图使其在本地计算机上与HTTPS一起使用。

I went through the following steps to enable HTTPS: 我通过以下步骤来启用HTTPS:

  • Added a mapping to the server name in my hosts file 在我的主机文件中添加了到服务器名称的映射
  • Installed a certificate (with the help of this post ) 安装了证书(借助此帖子
  • Reserved a URL ( https://+:10001/ ) 保留URL( https://+:10001/
  • Ran the service under the reserved URL 在保留的URL下运行服务

Starting the service: 启动服务:

var startOptions = new StartOptions();
startOptions.Urls.Add(baseUrl); // baseUrl is "https://+:10001/"
_webApplication = WebApp.Start<Startup>(startOptions);

If I disable Windows authentication (comment out the 2 lines with HttpListener above), I can access the service using the HTTPS protocol. 如果禁用Windows身份验证(用上面的HttpListener注释掉两行),则可以使用HTTPS协议访问该服务。 The browser recognizes the certificate. 浏览器可以识别证书。

When I enable Windows authentication, I keep getting 401 responses (in Fiddler I can see up to 6 401 responses for one request). 启用Windows身份验证后,我一直收到401个响应(在Fiddler中,一个请求最多可以看到6 401个响应)。 A browser keeps prompting me to log in, and fails after a number of attempts with a 401 code. 浏览器不断提示我登录,并且多次尝试输入401代码后失败。

I have been trying to find someone facing a similar problem. 我一直在寻找一个面临类似问题的人。 This post looked promising. 这篇文章看起来很有希望。 However, the author did not seem to have any issues with the .NET 4.5 version of OWIN. 但是,作者似乎对.NET 4.5版本的OWIN没有任何问题。

Could anyone please advise? 有人可以建议吗? Thank you! 谢谢!

Our problem was the authentication rather than SSL. 我们的问题是身份验证而不是SSL。

  • Using AuthenticationSchemes.Ntlm helped 使用AuthenticationSchemes.Ntlm帮助
  • The other problem was the correct registration of the server name within the organization, so that clients (developers' machines) could access it 另一个问题是组织中服务器名称的正确注册,以便客户端(开发人员的计算机)可以访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 https 使用代理 OWIN 自托管 Web API 的 Swashbuckle 方案问题 - https scheme issue with Swashbuckle using Proxied OWIN self-hosted Web API 依赖注入无法与Owin自托管Web Api 2和Autofac一起使用 - Dependency injection not working with Owin self-hosted Web Api 2 and Autofac 在自托管 OWIN Web API 中,如何在关机时运行代码? - In self-hosted OWIN Web API, how to run code at shutdown? .NET 6 中的自托管 Web API - Self-Hosted Web API in .NET 6 ASP.NET Core 3.1 Web API: can it be self-hosted as Windows service with https and use some certificate like IIS? - ASP.NET Core 3.1 Web API : can it be self-hosted as Windows service with https and use some certificate like IIS? 在ASP.NET自托管Web API上配置SSL - Configuring SSL on ASP.NET Self-Hosted Web API 自托管进程中 Web API 带点网核心 - Self-hosted In Process Web API with Dot net core 客户端证书映射自托管Owin端点中的身份验证 - Client Certificate Mapping Authentication in self-hosted Owin endpoint 使用Owin自托管的Web API中获取远程主机IP - Get Remote Host IP in Web API Self-Hosted Using Owin 当自托管OWIN服务器关闭时,如何向Web API操作发出取消信号? - How can I signal cancellation to Web API actions when the self-hosted OWIN server shuts down?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM