jexus手动跨域设置

AP.NET MVC默认跨域方法如下:

  1. <system.webServer>
  2.     <validation validateIntegratedModeConfiguration="false" />
  3.     <modules runAllManagedModulesForAllRequests="true" />
  4.     <httpProtocol>
  5.       <customHeaders>
  6.         <add name="Access-Control-Allow-Origin" value="*" />
  7.         <add name="Access-Control-Allow-Headers" value="Content-Type" />
  8.         <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
  9.       </customHeaders>
  10.     </httpProtocol>

但是这个在Jexus好像不起使用,于是手动增加代码,ASP.NET MVC 手动增加跨域设置,在basecontrol中增加如下代码:

  1.  protected override void OnResultExecuted(ResultExecutedContext filterContext)
  2.         {
  3.             base.OnResultExecuted(filterContext);
  4.  
  5.             filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
  6.             filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET");
  7.             db.Dispose();
  8.         }

最后效果如下:

posted @ 2018-05-02 22:02  三瑞  阅读(350)  评论(0编辑  收藏  举报