从 AuthorizationHandlerContext 对象中获取控制器和动作名称 [英] Get controller and action name from AuthorizationHandlerContext object

查看:32
本文介绍了从 AuthorizationHandlerContext 对象中获取控制器和动作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接受 AuthorizationHandlerContext context 参数的自定义需求处理程序

Hi I have a custom requirement handler with accepts the AuthorizationHandlerContext context parameter

当我调试时,我可以看到上下文对象包含Context.Resources.ActionDescription.ActionName

When i debug, i can see that the context object contains Context.Resources.ActionDescription.ActionName

但是在编写代码时我无法超越上下文.资源

But when writing the code i cant go beyond Context.Resources

似乎低层没有暴露.我想获取调用处理程序的操作名称和控制器名称.我该怎么做?

Seems the lower levels are not exposed. I want to get the action name and controller name that called the handler. How do i do this?

推荐答案

var mvcContext = context.Resource as AuthorizationFilterContext;
var descriptor = mvcContext?.ActionDescriptor as ControllerActionDescriptor;
if (descriptor != null)
{
    var actionName = descriptor.ActionName;
    var ctrlName = descriptor.ControllerName;      
}

这篇关于从 AuthorizationHandlerContext 对象中获取控制器和动作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆