本文介绍了asp Core mvc隐藏和排除Web Api控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有 ApiExplorerSettings 属性
[ApiExplorerSettings(IgnoreApi = true)] public async Task<IActionResult> MyMethod(int id)但这不会阻止api的客户端调用终结点方法.
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.
推荐答案最简单的MVC方法可能是使用 NonAction 属性,如下所示:
The simplest MVC approach might be to use the NonAction attribute, like so:
[ApiExplorerSettings(IgnoreApi = true)] [NonAction] public async Task<IActionResult> MyMethod(int id)另一种选择是将方法的访问修饰符从public更改为例如private具有相同的效果.
Another option is to just change the method's access modifier from public to e.g. private for the same effect.
更多推荐
asp.net Core mvc隐藏和排除Web Api控制器方法
发布评论