[英]How to set [NonAction] attribute on some actions of ASP.NET Core 5 Web API in startup
我需要在我的 ASP.NET Core 5 Web API 的某些操作上添加[NonAction]
或[ApiExplorerSettings(IgnoreApi = true)]
屬性,通過外部 json 文件或操作名稱示例列表啟動。
List<string> ActionNames = new()
{
"GetLastName",
"GetName",
"GetAge"
};
// I need to add [NonAction] on these actions in startup
ASP.NET Core 5 Web API 啟動時的一些動作如何設置[NonAction]屬性
如果您查看[NonAction]
屬性的詳細信息,它是從NonActionAttribute
class 派生的,這是一種Sealed
類型,如下所示:
此外,在ControllerActionDescriptor
中,我們有一個名為CustomAttributes
的屬性,它派生自MethodInfo
class,而CustomAttributes
只允許未set
,因此get
無法在 controller 上動態設置CustomAttributes
。如下所示:
因此,我們不能在 controller 上設置CustomAttributes
,因為它不允許。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.