简体   繁体   English

ASP.Net Core 3.1 - IIS 10.0 - Windows 认证

[英]ASP.Net Core 3.1 - IIS 10.0 - Windows Authentification

I have banged head lately on a Authentication issue on IIS/Windows Server 2016. I have two websites, each running ASP.Net Core WEB API, let us call them A and B. Both sites are running with Anonymous disabled, and Windows Authentication enabled, this is done to be able to get the name of Windows User calling the WEB API. I have banged head lately on a Authentication issue on IIS/Windows Server 2016. I have two websites, each running ASP.Net Core WEB API, let us call them A and B. Both sites are running with Anonymous disabled, and Windows Authentication enabled ,这样做是为了能够得到 Windows 用户调用 WEB API 的名称。

Each site works nicely, including getting the Username of the Windows user calling the WEB API.每个站点都运行良好,包括获取 Windows 用户的用户名,该用户调用 WEB API。

My issue is that Site A want's to call Site B's WEB API methods, this is done by using a HttpClient:我的问题是站点 A 想要调用站点 B 的 WEB API 方法,这是通过使用 HttpClient 完成的:

        var handler = new HttpClientHandler
        {
            UseDefaultCredentials = true,
            PreAuthenticate = true
        };
        HttpClient = new HttpClient(handler);
        HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

I keep getting a Unauthorized Http 401 when site A Web API calls site B's WEB API . I keep getting a Unauthorized Http 401 when site A Web API calls site B's WEB API . If I turn on Anonymous Authentication on Site B , it works fine.如果我在站点 B 上打开匿名身份验证,它工作正常。

If Site A is started outside IIS as an Console App, it also works very fine, because Site A is running in my user Context.如果站点 A 在 IIS 之外作为控制台应用程序启动,它也可以正常工作,因为站点 A 在我的用户上下文中运行。

My theory is that it is IIS that throws the 401, and not site B itself.我的理论是抛出 401 的是 IIS,而不是站点 B 本身。

Is there anything I need to do with the way that Site B is configured on the IIS to allow the API calls from site A?.在 IIS 上配置站点 B 以允许从站点 A 调用 API 的方式,我需要做些什么吗? My experience is that it doesn't matter what happens inside site B, the API call from site A is blocked before that point.我的经验是,站点 B 内部发生的事情并不重要,站点 A 的 API 调用在此之前被阻止。

Thanks in advance:-)提前致谢:-)

I quitted - and jumped to CORS instead - and IIS CORS Module, and got it working very nicely.我退出了 - 而是跳到 CORS - 和 IIS CORS 模块,并让它工作得很好。

IIS CORS Module has the abillity to handle CORS preflight request without colliding with Windows Authentication, and can easily be configured in web.config. IIS CORS Module has the abillity to handle CORS preflight request without colliding with Windows Authentication, and can easily be configured in web.config.

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM