How to run a method on startup of ALL Controllers?

Asked

Viewed 70 times

0

I have a static class that carries language in relation to cookie stored or the URL. Throughout controller I have to insert once the following method:

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

But there were cases where I forgot to add these calls and so all the views of controller X does not load the language the user is.

How do I run this Initialize() not only in one controller, but in all, including those to be added?

  • Did the answer resolve what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?

1 answer

1

Inherits the class Controller to another your where you customize the way you want, in this case putting this method, let’s call AppController, instead of inheriting from Controller inherits from his 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 from the programmer :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.