asp.net Core mvc hide and exclude Web Api Controller Method

三世轮回 提交于 2020-03-17 09:16:19

问题


I know there is the ApiExplorerSettings attribute

[ApiExplorerSettings(IgnoreApi = true)]
public async Task<IActionResult> MyMethod(int id)

But that does not stop a client of the api to call the endpoint method.

I need to know if there is an attribute that disables the endpoint and does not allow requests. I want to avoid doing it by modifying the routing mechanism.


回答1:


The simplest MVC approach might be to use the NonAction attribute, like so:

[ApiExplorerSettings(IgnoreApi = true)]
[NonAction]
public async Task<IActionResult> MyMethod(int id)

Another option is to just change the method's access modifier from public to e.g. private for the same effect.



来源:https://stackoverflow.com/questions/47328654/asp-net-core-mvc-hide-and-exclude-web-api-controller-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!