启用WCF服务CORS。获取HTTP 405:不允许的方法 [英] Enable CORS on WCF Service. Get HTTP 405: Method Not Allowed

查看:1911
本文介绍了启用WCF服务CORS。获取HTTP 405:不允许的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图启用WCF服务CORS。当我尝试从我的客户端发送一个请求,请求使用选项动词发送。我总是得到一个 HTTP 405:不允许的方法错误

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

如果我尝试使用招,并创建具有相同的请求在 POST 动词的反应似乎是正确的。

If I try using Fiddler and create the same request with the POST verb the response seems to be correct.

我试图删除 WEBDAV 本教程
http://brockallen.com/2012/10/18/cors-iis-and-webdav/ 但它似乎没有工作。

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.

我已经更新我的WCF使CORS参考教程的 http://enable-cors.org/server_wcf.html 。我不知道什么错误。响应似乎有CORS头

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

任何帮助将高度赞赏

PS:我不想做的问题非常大的和混乱。如果你想看看我的配置是让我知道,我可以分享

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

推荐答案

检查此链接的 http://praneeth4victory.wordpress.com/2011/09/29/405-方法 - 不容许/

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆