我怎样才能将调用特定的请求控制器动作的MethodInfo的? [英] How can i get the MethodInfo of the controller action that will get called given a request?

查看:94
本文介绍了我怎样才能将调用特定的请求控制器动作的MethodInfo的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器和动作这是负责处理403s由于用户在正确的角色不是。并先后获得原 RequestContext的导致异常。

I have a controller and action that's responsible for handling 403s due to the users not being in the correct roles. It has access to the original RequestContext that caused the exception.

我想什么能够做的是装饰自己的行为与他们做什么的描述,则允许用户通知他们的经理,请求访问包含在电子邮件中的描述。

What I would like to be able to do is decorate my actions with a description of what they do, then allow the user to notify their manager, requesting access including the description in an email.

因此​​,我怎么能制定出什么样的行动将被称为赋予​​ RequestContext的

So, how can I work out what action would be called given a RequestContext?

显然,这是更复杂,越来越控制器和动作的名字出了的RouteData ,因为经常有超载的操作方法等。

Obviously this is more complicated that getting controller and action names out of the RouteData since there are often overloads of an action method etc.

一旦我有的MethodInfo 那么容易得到的属性等。

Once I have the MethodInfo then it's easy to get attributes etc.

推荐答案

试图去解决它回顾是有点忌讳的,因为你可能需要使用反射来发现正确的方法 - 它可能会可以简单的插入所需的数据到 HttpContext.Items 为code其中授权失败的一部分?然后,它会从你的处理方式,通过 RequestContext.HttpContext.Items

Trying to work it out retrospectively is a bit of a can of worms, as you'd probably need to use reflection to discover the correct method - It would probably be simpler to insert the required data into the HttpContext.Items as part of the code where the authorization fails? It would then be available from your handling method through RequestContext.HttpContext.Items.

这篇关于我怎样才能将调用特定的请求控制器动作的MethodInfo的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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