ASP.NET MVC event that happens just before action is called?

前端 未结 3 1233
既然无缘
既然无缘 2021-02-06 12:23

I want to set the value of Thread.CurrentCulture based on some route data, but I can\'t find an event to hook to that fires after the routes are calculated and befo

3条回答
  •  醉酒成梦
    2021-02-06 13:18

    If you want to add the filter to all controllers, not just select ones, you can add it to the "global filters". You do this in Application_Start() in your Global.asax.cs file:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
    
        // Register global filter
        GlobalFilters.Filters.Add(new CustomFilterAttribute ()); // ADDED
    
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
    

提交回复
热议问题