在项目中新建 global.asmx 全局配置文件并添加如下代码即可:
参考代码,放在global.asax中
protected virtual void ApplicationBeginRequest(Object sender, EventArgs e)
{
#region Cross Domain Service
//以下代码提供跨域服务(包括“简单跨域”与“复杂跨域”,Web.config中不用再做设置)
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");//简单跨域
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,PUT,DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "*");
HttpContext.Current.Response.End();
}
#endregion
}
来源:oschina
链接:https://my.oschina.net/u/3097161/blog/3197492