0
我是WCF的初學者,我一直在嘗試爲在我的IIS中託管的WCF服務啓用CORS。我已經經歷了幾個帖子和Stack Overflow問題,所有的答案都讓我看到了不同的解決方案,而且它們都不起作用。在wcf中啓用cors -ajax
有人可以解釋我如何實現這個?我嘗試創建一個global.asax並添加begin_request事件來設置標題,但它沒有改變。 這是我使用的:
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();
}
}
我應該從哪裏開始的這一點,這是實現這一目標的最佳途徑?
你有沒有試過這個http://enable-cors.org/server_wcf.html? – 2014-11-06 07:45:12
@MajoB是的,但我無法正確配置它,它給了我很多例外 – 2014-11-07 06:51:31
您是否已將'Access-Control-Allow-Origin'添加到網絡配置 – 2015-10-03 16:56:59