首页 > Windows开发 > 详细

Enable OWIN Cross-origin Request

时间:2014-07-03 17:35:07      阅读:420      评论:0      收藏:0      [点我收藏+]

微软出了一套解决方案可以解决 “允许WebAPI的 CORS 请求”


http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api


如果你同时使用了OWIN,即使使用了这个,也不能使OWIN 允许 cross-origin 请求。

OWIN 是基于kantana的一套OAUTH2.0解决方案。


所以要使用 DLL Microsoft.OWIN.Cros

I installed Microsoft.Owin.Cors package on the API Server. In Startup.Auth.cs file, under public void ConfigureAuth(IAppBuilder app), I added in

app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

In WebApiConfig.cs, under public static void Register(HttpConfiguration config), I added in these lines:

// Cors
var cors = new EnableCorsAttribute("*", "*", "GET, POST, OPTIONS");
config.EnableCors(cors);

或者 最直接的方法()!!!!

 <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
      </customHeaders>
  </httpProtocol>

把这段加在web.config的<system.webServer>节点下,成功!


Enable OWIN Cross-origin Request,布布扣,bubuko.com

Enable OWIN Cross-origin Request

原文:http://blog.csdn.net/lglgsy456/article/details/36439653

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