How to execute a method at the initialization of ALL Controllers?

0

I have a static class that loads the language against the cookie stored or the URL. In every controller I have to insert the following method once:

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
    LanguageCookieController.Load(); //Método que carrega
    base.Initialize(requestContext);
}

But there have been cases where I forgot to add these calls and so all X controller views do not carry the language the user is on.

How do I execute this Initialize() not only on a controller , but on all, including the ones that will be added?

    
asked by anonymous 28.11.2018 / 13:07

1 answer

1

Inherit the class Controller to another your where you customize it the way you want, in this case putting this method, let's call AppController , there instead of inheriting from Controller inherits from its new class AppController , inheritance was made for this.

Of course you can forget to inherit from yours, but not all problems can be solved when the problem is with the programmer:)

    
28.11.2018 / 13:16