asp.net Core mvc隐藏和排除Web Api控制器方法

编程入门 行业动态 更新时间:2024-10-26 02:35:08
本文介绍了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控制器方法

本文发布于:2023-11-16 20:59:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   方法   Core   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!