我正在使用一个现有的Web API,在其中我需要基于HttpPost进行所有操作。为了实现这一点,我使用了这样的配置。
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}",
defaults: new { id = RouteParameter.Optional },
constraints: new { httpMethod= new HttpMethodConstraint(HttpMethod.Post) }
);
但这不适用于名称以“ Get”开头的动作。但是,当我用[HttpPost] atrribute这样的装饰动作时,效果很好
[HttpPost]
public IHttpActionResult GetUserByName()
有很多这样的动作,我想避免用[HttpPost]属性来修饰每个动作。有什么办法可以全局设置[HttpPost]属性?