简体   繁体   English

Web API - 在 IIS 上找不到 OWIN TokenEndPointPath 404

[英]Web API - OWIN TokenEndPointPath not found 404 on IIS

I just tested a working Web.Api named "WebApiServizio1" protected with a OAuth2 BearerAuthentication (Owin implementation) and it's been deployed on the root of my IIS WebServer.我刚刚测试了一个名为“WebApiServizio1”的工作 Web.Api,它受 OAuth2 BearerAuthentication(Owin 实现)保护,它已部署在我的 IIS WebServer 的根目录上。

I would like to change the current webserver configuration moving the "WebApiServizio1" web.Api inside a new website WEBAPI.我想更改当前的网络服务器配置,将“WebApiServizio1”web.Api 移动到新网站 WEBAPI 中。 So I can host more then one api (with the same host and port).所以我可以托管多个 API(具有相同的主机和端口)。

IIS: WEBAPI webSite Port:80 (AppPool: Integrated, 4.0) IIS: WEBAPI 网站端口:80(AppPool:集成,4.0)

预期的 IIS 配置

PROBLEM But when I try to autenticate with the OWIN Middleware I can't obtain the Token, I get a "404 - not found" response trying to reach the TokenEndpointPath.问题但是当我尝试使用 OWIN 中间件进行身份验证时,我无法获得令牌,我得到一个“404 - 未找到”响应,试图到达 TokenEndpointPath。

Recap:回顾:

http://localhost/WebApiServizio1/ HTTP 403.14 - Forbidden CORRECT! http://localhost/WebApiServizio1/ HTTP 403.14 - 禁止正确! http://localhost/WebApiServizio1/oauth/token/ HTTP 404.0 - Not Found - :( http://localhost/WebApiServizio1/oauth/token/ HTTP 404.0 - 未找到 - :(

This the current Owin.Startup configuration:这是当前的 Owin.Startup 配置: 启动配置

Client configuration:客户端配置: 客户端配置

Any ideas?有任何想法吗?

the problem seems to be the trailing / after token in your PostAsync() call 问题似乎出在PostAsync()调用中的尾随/ token之后

instead write 改写

using (HttpResponseMessage response = await client.PostAsync("/oauth/token", new FormUrlEncodedContent(values))) 

and it should work. 它应该工作。

On a side note: when you initialize your RefreshTokenProvider with DateTime.UtcNow.AddHours(8) , all your refresh tokens are valid until 8 hours after the programm was startet instead of 8 hours after the access token is issued. 附带一提:当您使用DateTime.UtcNow.AddHours(8)初始化RefreshTokenProvider时,所有刷新令牌在计划启动后8个小时内有效,而在发出访问令牌后8个小时内有效。

Check that your Owin Startup event is even firing and it attaches this url that is not found. 检查您的Owin Startup事件是否甚至正在触发,并附加未找到的该URL。 In my case it wasn't due to wrong namespace. 就我而言,这不是由于名称空间错误引起的。

在我的情况下,我直接部署了bin \\文件夹,但是我忘了发布webapi,一旦完成,一切都像一个魅力^ _ ^

在此处输入图片说明

In my case in AllowInsecureHttp was set false, which was creating the error on http.在我的情况下,AllowInsecureHttp 设置为 false,这会在 http 上创建错误。

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

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