在WCF服务上启用CORS。获取HTTP 405:方法不允许 [英] Enable CORS on WCF Service. Get HTTP 405: Method Not Allowed
问题描述
我尝试在WCF服务上启用CORS。当我尝试从我的客户端发送请求时,使用 OPTIONS
动词发送请求。我总是得到一个 HTTP 405:方法不允许
错误
如果我尝试使用Fiddler并创建相同的请求 POST
动词的回应似乎是正确的。
我试图移除 webDAV
在教程的帮助下
:
protected void Application_BeginRequest(object sender,EventArgs e)
{
HttpContext.Current.Response.AddHeader(Access-Control-Allow-Origin,*);
if(HttpContext.Current.Request.HttpMethod ==OPTIONS)
{
HttpContext.Current.Response.AddHeader(Cache-Control,no-cache);
HttpContext.Current.Response.AddHeader(Access-Control-Allow-Methods,GET,POST);
HttpContext.Current.Response.AddHeader(Access-Control-Allow-Headers,Content-Type,Accept);
HttpContext.Current.Response.AddHeader(Access-Control-Max-Age,1728000);
HttpContext.Current.Response.End();
}
}
I am trying to enable CORS on a WCF service. When I try to send a request from my client, the request is sent using the OPTIONS
verb. I always get a HTTP 405: Method not allowed
error
If I try using Fiddler and create the same request with the POST
verb the response seems to be correct.
I have tried to remove webDAV
with the help of the tutorial
http://brockallen.com/2012/10/18/cors-iis-and-webdav/ but it doesnt seem to work.
I have updated my WCF to enable CORS referring to the tutorial http://enable-cors.org/server_wcf.html. I am not sure what is going wrong. The response seem to have the CORS header
Any help would be highly appreciated.
PS: I did not want to make the question very big and confusing. If you would like to look at my config be let me know and I can share it
Check this link http://praneeth4victory.wordpress.com/2011/09/29/405-method-not-allowed/:
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
这篇关于在WCF服务上启用CORS。获取HTTP 405:方法不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!