在做公家的项目,有个奇葩的规定,Http请求 不能用Put
和Delete
。
怎么在使用Abp,自动生成的Api,全局修改原有规则,将修改、删除都改成Post
呢?
只需要,在Host项目的XXXModule
类中,重写的PreConfigureServices
方法,加上如下代码即可。
HttpMethodHelper.ConventionalPrefixes = new Dictionary<string, string[]>
{{ "GET", ["GetList", "GetAll", "Get"] },{ "POST", ["Create", "Add", "Insert", "Post", "Put", "Update", "Delete", "Remove", "Patch"] }
};
如果想指定方法,则。只需要项目中添加Microsoft.AspNetCore.Mvc.Core
的NuGet
包,可以使用ASP.NET Core
的标准属性([HttpPost]
、[HttpGet]
、[HttpPut]
……)