ajax跨域请求wcf,ajax wcf 指定某个域名 进行跨域访问

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值