ASP.NET MVC4 WEB API跨域
web.config文件里加些东西即可
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="AuthToken, Authorization, Origin, Content-Type, Accept, X-Requested-With" /> <add name="Access-Control-Allow-Methods" value="GET, PATCH, POST, PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol> <!--其他代码--> </system.webServer>
另外在新建mvc4 的web api项目时/help会显示所有接口的名字和参数的,需要在WebApiConfig.cs类中加入{action}才会把所有的方法都显示出来的,要不然就只会显示get,post,put,delete这些方法而已
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } );
标签:MVC4,WEB,ASP,跨域,API,NET From: https://www.cnblogs.com/niunan/p/17552356.html