自ASP.NET MVC ActionFilterAttribute - 挂钩从来没有被调用 [英] Custom ASP.NET MVC ActionFilterAttribute - hooks never get called

查看:271
本文介绍了自ASP.NET MVC ActionFilterAttribute - 挂钩从来没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜我真的试图做一些事情,似乎还挺容易的,有文件证明的方式,但由于某种原因,它不会那么容易。

Hi I`m trying to do something that seems kinda easy, and is documented that way but for some reason its not going that easy.

Basiclly我写的是这样的:

Basiclly I wrote something like this:

public class CacheControllAttribute : ActionFilterAttribute
{
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    { 
        //do something
        base.OnResultExecuting(filterContext);
    }
}

然而,当我试图用这个在这样的一个作用的结果:

However when i try and use this on an action result like this:

[CacheControllAttribute]
public ActionResult SomeAction()
{
    //whatever
}

我的自定义功能,重写永远不会调用...

My custom overriden function never gets called...

在这个任何想法?或如何不同的方式实现这一点?

any ideas on this? or how to implement this differently?

推荐答案

终于想通了,这是最后的事实,我已经把过滤器上已在事实上被一个ActionResult功能的功能,但它是通过调用它的另一种方法返回,所以过滤器只能被在入口点行动执行一次。

Finally figured out, it was in the end the fact that I have been putting the filter on a function that has in fact been an ActionResult function, but it was returned by another method that called it, so the filters are only being executed once on the entry point Action.

这篇关于自ASP.NET MVC ActionFilterAttribute - 挂钩从来没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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