zl程序教程

您现在的位置是:首页 >  后端

当前栏目

webapi 405 method not allowed

WebAPI not method Allowed 405
2023-09-11 14:21:23 时间

问题的原因:创建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]
........