簡體   English   中英

ASP.NET Core 5 Web API 啟動時的一些動作如何設置[NonAction]屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM