我已在我的应用程序中启用了全局CORS支持
this.Plugins.Add(new CorsFeature(
allowCredentials: true,
allowedHeaders: "Content-Type, Authorization",
allowedOrigins: "*",
allowedMethods: "GET, POST, OPTIONS"
));
this.GlobalRequestFilters.Add((httpReq, httpRes, httpDto) =>
{
if (httpReq.Verb == "OPTIONS")
{
httpRes.EndRequest();
}
});
在我的路线中,我添加了OPTIONS动词(可能没有必要)
[Route("/Mailers", "POST, GET, OPTIONS")]
public class MailersRequest {
public List<Int64> Properties { get; set; }
}
除了IE 11之外,我尝试过的所有浏览器都能很好地运行。新的Edge浏览器和Chrome一样好。在IE 11上,对/ mailers的OPTIONS请求根本没有响应。以下是请求标题:
Request URL: https://api.blahblah.com:4443/mailers
Request Method: OPTIONS
Accept: */*
Accept-Encoding: gzip, deflate
Access-Control-Request-Headers: accept, content-type
Access-Control-Request-Method: POST
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 0
Host: api.blahblahblah.com:4443
Origin: https://www.housesellersource.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
请求无限期地处于Pending状态。同样,在其他浏览器中一切正常。
有什么想法吗?谢谢!
答案 0 :(得分:1)
首先,您无需为处理OPTIONS请求指定GlobalRequestFilters
,即:
this.GlobalRequestFilters.Add((httpReq, httpRes, dto) => {
if (httpReq.Verb == "OPTIONS")
httpRes.EndRequest();
});
由于OPTIONS已经handled by ServiceStack's CorsFeature。
但它似乎是issue with CORS in IE is that requires a valid P3P Policy。