asp.net web api 如何设置允许后台跨域访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API 配置和服务 // Web API 路由 config.MapHttpAttributeRoutes(); config.Formatters.Remove(config.Formatters.XmlFormatter); //config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain")); config.Formatters.JsonFormatter.SupportedMediaTypes.Add( new MediaTypeHeaderValue( "application/json" )); config.Formatters.JsonFormatter.SupportedMediaTypes.Add( new MediaTypeHeaderValue( "multipart/form-data" )); config.Formatters.JsonFormatter.SupportedMediaTypes.Add( new MediaTypeHeaderValue( "application/octet-stream" )); config.Routes.MapHttpRoute( name: "DefaultApi" , routeTemplate: "api/{controller}/{id}" , defaults: new { id = RouteParameter.Optional } ); //设置cors允许跨越 config.EnableCors( new EnableCorsAttribute( "*" , "*" , "GET, POST" )); } } |
用nuget 先安装Microsoft.AspNet.WebApi.Cors 引用,然后配置上面的配置
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
2013-09-06 SQL Server Data Tool 嘹解(了解)一下 SSDT -摘自网络