C# 解决跨域问题
2021-01-19 02:17
标签:template param efault oid class pos reg ring put WebApiConfig.cs 添加 config.EnableCors(); Controllers 在API的类上面使用特性标注 [EnableCors(origins: "*", headers: "*", methods: "GET,POST,PUT,DELETE")] C# 解决跨域问题 标签:template param efault oid class pos reg ring put 原文地址:https://www.cnblogs.com/liushoushou/p/12166180.html public static void Register(HttpConfiguration config)
{
// Web API 配置和服务
//跨域配置
config.EnableCors();
// Web API 路由
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
[EnableCors(origins: "*", headers: "*", methods: "GET,POST,PUT,DELETE")]
public class TextController : ApiController
{
[HttpGet]
public string Get()
{
return "Success";
}
}