本文介绍了从AuthorizationHandlerContext对象获取控制器和动作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义需求处理程序,它接受 AuthorizationHandlerContext上下文
参数
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 containsContext.Resources.ActionDescription.ActionName
但是在编写代码时,我无法超越
Context.Resources
But when writing the code i cant go beyondContext.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对象获取控制器和动作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!