简体   繁体   English

OWIN预检请求未处理

[英]OWIN preflight requests are not processed

All preflight requests from browsers to my Self-Host OWIN WebAPI are not processed by Middleware. 中间件不处理从浏览器到我的自托管OWIN WebAPI的所有预检请求。 If I make OPTIONS request from Postman they are processed. 如果我向邮递员提出了OPTIONS请求,则它们将被处理。 Why is such a behaviour? 为什么会有这样的行为?

Request URL: http://localhost:9000/api/v1/conversations/create?connectionId=13509f44-eacb-4950-8cc8-71bd37098975 请求网址: http:// localhost:9000 / api / v1 / conversations / create?connectionId = 13509f44-eacb-4950-8cc8-71bd37098975

Request Method:OPTIONS 请求方法:OPTIONS

Status Code:401 Unauthorized Remote 状态码:401未经授权的遥控器

Address:[::1]:9000 地址:[:: 1]:9000

Accept: / 接受: /

Accept-Encoding:gzip, deflate, sdch, br 接受编码:gzip,deflate,sdch,br

Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4 接受语言:ru-RU,ru; q = 0.8,en-US; q = 0.6,en; q = 0.4

Access-Control-Request-Headers:content-type 访问控制请求标头:内容类型

Access-Control-Request-Method:POST 访问控制请求方法:POST

Connection:keep-alive 连接方式:保持活跃

Host:localhost:9000 主机:localhost:9000

Origin: http://localhost:8080 来源: http:// localhost:8080

Referer: http://localhost:8080/ 引荐来源: http:// localhost:8080 /

User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 56.0.2924.87 Safari / 537.36

Response Headers for Chrome: Chrome响应标题:

Content-Length:0 内容长度:0

Date:Wed, 08 Feb 2017 04:17:26 GMT 日期:2017年2月8日,星期三04:17:26 GMT

Server:Microsoft-HTTPAPI/2.0 伺服器:Microsoft-HTTPAPI / 2.0

WWW-Authenticate:NTLM WWW认证:NTLM

Response headers for Postman: 邮递员的响应标头:

Access-Control-Allow-Credentials →true 访问控制允许凭证→true

Access-Control-Allow-Origin →chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop 访问控制允许来源→chrome扩展名:// fhbjgbiflinjbdggehcddcbncdddomop

Allow →POST 允许→POST

Content-Length →76 内容长度→76

Content-Type →application/json; 内容类型→application / json; charset=utf-8 字符集= utf-8

Date →Wed, 08 Feb 2017 04:21:02 GMT 日期→2017年2月8日星期三04:21:02 GMT

Server →Microsoft-HTTPAPI/2.0 服务器→Microsoft-HTTPAPI / 2.0

I added fake middleware to my appbuilder: 我在Appbuilder中添加了伪造的中间件:

public void BuildWebApi(IAppBuilder appBuilder)
    {
        appBuilder.Use(async (ctx, next) =>
        {
            await next();
        });

and put breakpoint to line "await next()". 并将断点放置到“ await next()”行。 So breakpoint doesn't stop while browser makes preflight request and stops while postman OPTIONS response. 因此,断点不会在浏览器发出预检请求时停止,而在邮递员OPTIONS响应时停止。

Solved this by 解决了

HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
listener.AuthenticationSchemeSelectorDelegate = request =>
{
   if (request.HttpMethod == "OPTIONS")
   {
       return AuthenticationSchemes.Anonymous;
   }
};

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

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