.net cros 跨域的坑
来源:互联网 发布:做数据库前景如何 编辑:程序博客网 时间:2024/06/06 09:54
Startup类中加入
public partial class Startup { public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); ConfigureAuth(app); string ff = ConfigurationManager.AppSettings["origins"]; config.EnableCors(new EnableCorsAttribute(ff, "*", "*")); config.Services.Replace(typeof(IAssembliesResolver), new ExtendedDefaultAssembliesResolver()); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First(); jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); } }
可是加入了微软的identity后,验证时跨域还需要到ApplicationOAuthProvider加入这个方法
private void setCrosUrl(OAuthGrantResourceOwnerCredentialsContext context) { string origin = context.Request.Headers["origin"]; if (ConfigurationManager.AppSettings["origins"].Contains(origin)) { context.OwinContext.Response.Headers.Remove("Access-Control-Allow-Origin"); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { origin }); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "GET,POST,PUT" }); } }
配置文件:
<add key="origins" value="http://localhost:64737,http://localhost:56504" />
阅读全文
0 0
- .net cros 跨域的坑
- cros跨域配置
- CROS代理跨域
- Ionic CROS 跨域问题
- tomcat跨域访问(CROS)
- spring中解决CROS跨域请求的方案
- 服务器端跨域访问(CROS)解决方案
- 跨域技术(JSONP与CROS)
- cros及jsond跨域处理
- 浅析CROS的实现
- CROS
- cros
- 客户端跨域访问(CROS)之jsonp详解
- LINK - Windows Azure Storage - 跨域访问策略 CROS
- Spring MVC通过CROS协议解决跨域问题
- 配置 cros Java 前后端分离跨域请求
- SpringBoot(六):SpringBoot使用CROS解决跨域问题
- Django解决跨域访问报错/Cros问题
- 如何扩展 Azure 资源组中虚拟机的 OS 驱动器
- 从硅谷到北京的FinTech双城记: 将区块链落地华尔街的PeerNova造访智链ChainNova
- 文章标题
- WPF DataGridCheckBoxColumn列不更新问题方案
- D
- .net cros 跨域的坑
- 【Python】报错NameError: name 'reload' is not defined
- 注解的作用
- 一张图详解linux中的top命令
- Android Studio -修改LogCat的颜色、字体
- log4j PatternLayout 配置
- 【WC2016模拟】最假女选手
- kotlin开发Android入门篇七Kotlin与Java相互调用
- Caffe学习系列****