获取 ASP.NET-Core 2.2 控制器中的控制器名称和方法名称

Posted

技术标签:

【中文标题】获取 ASP.NET-Core 2.2 控制器中的控制器名称和方法名称【英文标题】:Get the Controller Name and Method Name in ASP.NET-Core 2.2 Controller 【发布时间】:2020-01-04 14:30:05 【问题描述】:

我知道在asp.net-core 2.2中,我可以得到动作名称如下:

ControllerContext.ActionDescriptor.ActionName

但我正在寻找一种方法来获取 asp.net-core 2.2 中当前请求/页面的控制器名称

我将不胜感激。

谢谢

【问题讨论】:

【参考方案1】:

您可以在

中访问控制器名称
ControllerContext.ActionDescriptor.ControllerName

属性,假设操作描述符是ControllerActionDescriptor 类型

参考ControllerActionDescriptor.ControllerName

【讨论】:

【参考方案2】:

我知道已经晚了,但也许有人可以从中受益

ControllerName: ControllerContext.ActionDescriptor.ControllerName 
ActionName: ControllerContext.ActionDescriptor.ActionName

【讨论】:

以上是关于获取 ASP.NET-Core 2.2 控制器中的控制器名称和方法名称的主要内容,如果未能解决你的问题,请参考以下文章

ASP.Net-Core 中的自定义身份验证

从类库访问 Asp.net-core 中的 appsetting.json

SqlException:INSERT 语句与 FOREIGN KEY 约束冲突 - asp.net-core

ASP .NET Core 身份登录管理器

为啥 ASP.NET-Core 应用程序会收到错误消息“此平台不支持锁定/解锁文件区域”。在 MacOS 上部署时?

我可以通过使用 cookie 自动重新登录到我的 SignInManager 和 UserManager (Identity) -> Asp.Net-Core Identity (Deploye