首页 > 代码库 > cors解决webapi post时报错405 method not allowed

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

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