首页 > Windows开发 > 详细

WebApi表头设置跨域

时间:2017-02-06 12:38:00      阅读:336      评论:0      收藏:0      [点我收藏+]
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            var setting = System.Configuration.ConfigurationManager.AppSettings;
            var cors = new EnableCorsAttribute("http://192.168.3.15:3000,http://192.168.3.15:3002", "*", "GET,POST,PUT,DELETE,OPTIONS")
            {
                SupportsCredentials = true
            };
            config.EnableCors(cors);

            // Web API 路由
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/",
                defaults: new { id = RouteParameter.Optional }, constraints: new { id = @"\d+" }
            );
        }
    }

或者 但在config不可以配置多个ip地址

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="http://192.168.6.43:3000" />
         <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type" />
        <add name="Access-Control-Allow-Method" value="GET,POST,OPTIONS" />
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

 

WebApi表头设置跨域

原文:http://www.cnblogs.com/lgxlsm/p/6369441.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!