cors解决webapi post时报错405 method not allowed

nuget控制台敲入以下命令:
Install-Package Microsoft.AspNet.WebApi.Cors IncludePrerelease



打开WebApiConfig.cs添加如下红色标注行

public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);

// Web API 配置和服务

// Web API 路由
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}

}

 From:http://www.cnblogs.com/xuejianxiyang/p/6210065.html
posted @ 2016-12-22 10:16  Ace001  阅读(3612)  评论(0编辑  收藏  举报