gpt4 book ai didi

asp.net-mvc - 在调用操作之前发生的 ASP.NET MVC 事件?

转载 作者:行者123 更新时间:2023-12-04 16:26:31 26 4
gpt4 key购买 nike

我想设置Thread.CurrentCulture的值基于一些路由数据,但我找不到在计算路由之后和调用 action 方法之前触发的事件。

有任何想法吗?

最佳答案

你可以写一个自定义 action filter attribute :

public class CustomFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// This method is executed before calling the action
// and here you have access to the route data:
var foo = filterContext.RouteData.Values["foo"];
// TODO: use the foo route value to perform some action

base.OnActionExecuting(filterContext);
}
}

然后你可以用这个自定义属性装饰你的基本 Controller 。这是一个 blog post说明了此类过滤器的示例实现。

关于asp.net-mvc - 在调用操作之前发生的 ASP.NET MVC 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4104107/

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