我正在尝试在 WCF 服务上启用 CORS。当我尝试从我的客户端发送请求时,请求是使用 OPTIONS 动词发送的。我总是收到 HTTP 405: Method not allowed 错误
如果我尝试使用 Fiddler 并使用 POST 动词创建相同的请求,响应似乎是正确的。
我已尝试在教程的帮助下删除 webDAV http://brockallen.com/2012/10/18/cors-iis-and-webdav/但它似乎不起作用。
我已更新我的 WCF 以启用 CORS,引用教程 http://enable-cors.org/server_wcf.html .我不确定出了什么问题。响应似乎有 CORS header
如有任何帮助,我们将不胜感激。
PS:我不想让这个问题变得很大和困惑。如果您想查看我的配置,请告诉我,我可以分享它
请您参考如下方法:
检查此链接 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();
}
}
