Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ControllerContext中的ActionDescriptor_C#_Asp.net Mvc 3_Controller_Controllercontext - Fatal编程技术网

C# ControllerContext中的ActionDescriptor

C# ControllerContext中的ActionDescriptor,c#,asp.net-mvc-3,controller,controllercontext,C#,Asp.net Mvc 3,Controller,Controllercontext,假设我只能访问ControllerContext而不能访问Action\uuuuuuuuuuuuuu上下文获取当前正在执行的ActionDescriptor的最佳方法是什么 到目前为止,我找到的唯一方法是: new ReflectedControllerDescriptor(context.Controller.GetType()) .FindAction(context, context.RouteData.GetRequiredString("action")); 这是最佳方法吗

假设我只能访问
ControllerContext
而不能访问
Action\uuuuuuuuuuuuuu上下文
获取当前正在执行的ActionDescriptor的最佳方法是什么

到目前为止,我找到的唯一方法是:

new ReflectedControllerDescriptor(context.Controller.GetType())
    .FindAction(context, context.RouteData.GetRequiredString("action"));
这是最佳方法吗


类名为ReflectedControllerDescriptor这一事实让我想知道这个操作是否有很大的成本,因为它将在每个页面请求上执行?与此相关的是,这个类是否在内部缓存,或者我是否应该显式地缓存ReflectedControllerDescriptors?

对MVC源代码进行一些挖掘,这几乎是最理想的方式,而无需复制您已经在做的事情所需的所有方法。但是,我不明白为什么不能缓存找到的操作,以便后续调用更高效

内部
ReflectedControllerDescriptor
也会缓存结果,尽管这似乎有点开销,因为它每次都会检查所有属性。它看起来适用于
httpposattribute
之类的东西


我的建议是坚持使用您正在使用的内容,而不是自己缓存它。如果由于某种原因,底层方法的工作方式发生了变化,那么您已经是最新的,不必担心更改存储缓存项的方式。

深入挖掘MVC源代码,这几乎是最理想的方式,而无需复制您已经在做的事情所需的所有方法。但是,我不明白为什么不能缓存找到的操作,以便后续操作更高效。此外,ReflectedControllerDescriptor确实使用反射来获取操作,因为它不仅查看方法,还查看附加到方法的属性。(ReflectedControllerDescriptor也会缓存结果)@BuildStarted这样就可以缓存
ReflectedControllerDescriptor
中的反射用法,但可以说我可以缓存对FindAction的调用?是的,你可以。ReflectedControllerDescriptor中仍有一些额外的属性处理(即使是缓存的操作),但它似乎并不是任何过程密集型的。