Hi fss,
你是怎么实现ajax wcf发布后可以被任意域名访问的?
根据我的理解和测试,创建一个新的wcf ajax enabled service是不支持跨域访问的。需要自己加功能来实现跨域访问,一般是通过添加Global.asax和下面的代码,在下面的代码里可以通过“Access-Control-Allow-Origin”配置特定域名。
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("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();
}
}
我不确定你是怎么实现跨域访问的。
Best Regards,
Edward
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.