cors解決webapi post時報錯405 method not allowed




打開WebApiConfig.cs添加以下紅色標註行
nuget控制檯敲入如下命令:
Install-Package Microsoft.AspNet.WebApi.Cors IncludePrerelease

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

// Web API 配置和服務api

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

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

}code

 From:http://www.cnblogs.com/xuejianxiyang/p/6210065.html
相關文章
相關標籤/搜索