gpt4 book ai didi

c# - 自定义 ASP.NET MVC ActionFilterAttribute - 永远不会调用 Hook

转载 作者:可可西里 更新时间:2023-11-01 03:03:29 30 4
gpt4 key购买 nike

您好,我正在尝试做一些看起来很简单的事情,并且以这种方式进行了记录,但由于某种原因,它并没有那么容易。

基本上我是这样写的:

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

然而,当我尝试在这样的操作结果上使用它时:

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

我的自定义覆盖函数从未被调用...

对此有什么想法吗?或者如何以不同的方式实现?

最佳答案

这可能是个愚蠢的建议,但您是否将其添加到您的 global.asax 中?
这是我的一个应用程序的示例:

public class MvcApplication : System.Web.HttpApplication     
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new LogonAuthorize());
filters.Add(new HandleErrorAttribute());
}
}

关于c# - 自定义 ASP.NET MVC ActionFilterAttribute - 永远不会调用 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6510362/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com