webapi 405 method not allowed

问题的原因:创建webapi controller时,习惯创建了mvc的controller,而非api controller。导致引用包有问题。


这两天搞webapi开发的时候,遇见了405错误。

我贴一下解决的方式:


controller中添加如下引用。

using System.Net;
using System.Net.Http;
using System.Web.Http;

删除

using System.Web.Mvc;

Action头部添加相应的请求方式

[HttpPost]
[HttpGet]
........



原文地址:https://www.cnblogs.com/hanjun0612/p/9779865.html