jexus手动跨域设置
AP.NET MVC默认跨域方法如下:
- <system.webServer>
- <validation validateIntegratedModeConfiguration="false" />
- <modules runAllManagedModulesForAllRequests="true" />
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Headers" value="Content-Type" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
- </customHeaders>
- </httpProtocol>
但是这个在Jexus好像不起使用,于是手动增加代码,ASP.NET MVC 手动增加跨域设置,在basecontrol中增加如下代码:
- protected override void OnResultExecuted(ResultExecutedContext filterContext)
- {
- base.OnResultExecuted(filterContext);
- filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
- filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET");
- db.Dispose();
- }
最后效果如下: