Access-Control-Allow-Methods不允许使用AngularJS补丁方法PATCH

时间:2015-09-25 20:32:11

标签: c# asp.net angularjs

您好我正试图从AngularJS向ServiceStack发送PATCH请求,收到此错误:

  

Access-Control-Allow-Methods不允许使用PATCH方法。

这是请求标题:

Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: PATCH
Origin: 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: https://pankajb1.dev.ma.net/ui/static/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6

这是回复:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 0
Server: Microsoft-IIS/7.5
X-Powered-By: ServiceStack/3.959 Win32NT/.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 25 Sep 2015 20:23:51 GMT

1 个答案:

答案 0 :(得分:2)

默认情况下CorsFeature不允许PATCH(will in next v4.0.48 release)。

与此同时,您可以在注册CorsFeature时指定CORS可用的方法,例如:

Plugins.Add(new CorsFeature(
    allowedMethods: "GET, POST, PUT, DELETE, PATCH, OPTIONS"));