根据Microsoft Documentation,在动作选择一节中,它指出:
- 如果以上都不是,则该方法支持POST。
醇>
有没有办法更改此默认行为以将HttpGet用作操作的默认ActionVerb?
答案 0 :(得分:1)
您链接的文档引用了IHttpActionSelector.SelectAction
方法作为操作选择的来源,而ApiControllerActionSelector
是默认实现。
如果您查看the source code,就可以看到the default implementation of that interface确实是ApiControllerActionSelector
类。如果查看ApiControllerActionSelector
实现,您可以看到它认为是有效路由的每种方法的it creates a ReflectedHttpActionDescriptor
。然后,当您查看ReflectedHttpActionMethod
,you can see how the default of POST is applied时,所有其他记录的识别替代动词的策略都会失败。
因此,要回答您的问题,您可以编写一个新的IHttpActionSelector
实现,该实现返回HttpActionDescriptor
,它使用的默认行为与您在ApiControllerActionSelector
中找到的默认行为不同。
或者,您可以应用[HttpGet]
属性和/或使用“获取”前缀命名该操作并将其称为一天。