C# 解决跨域问题
WebApiConfig.cs
添加 config.EnableCors();
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 } ); }
Controllers
在API的类上面使用特性标注
[EnableCors(origins: "*", headers: "*", methods: "GET,POST,PUT,DELETE")]
[EnableCors(origins: "*", headers: "*", methods: "GET,POST,PUT,DELETE")] public class TextController : ApiController { [HttpGet] public string Get() { return "Success"; } }
相关推荐
逍遥友 2020-11-20
hellowordmonkey 2020-11-02
gloria0 2020-10-26
zyshappy 2020-08-16
pythonwangjunji 2020-08-16
Equation 2020-08-09
iamjiyu 2020-07-21
winxcoder 2020-07-18
lepton 2020-07-04
zzdadexiaoha 2020-06-28
ajuan 2020-06-25
tosim 2020-06-24
wghou 2020-06-21
yudiewenyuan 2020-06-21
JessePinkmen 2020-06-14
heimu 2020-06-12
limx 2020-06-11
zghover 2020-06-11