1

Where would such code go? Is there a commonly executed block inside Asp.net mvc 3 application - something that gets executed every time any page is loaded?

2 Answers 2

2

You can do this by two ways: First, you can inherit a base Controller from System.Web.Mvc.Controller. Then you use this base class inherits for your application. By this way, you can handle all action executions by overriding OnActionExecuting method of your base controller.

Second and better solution is using Custom Action Filters. Create a custom filter and register it globally in Global.asax file like this:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new YourCustomFilter());
}
Sign up to request clarification or add additional context in comments.

Comments

1

Global.asax (ex: http://www.dotnetcurry.com/ShowArticle.aspx?ID=126) or inside the _Layout, it depends on what you're doing.

Just so you know the Global.asax file is also available in ASP.NET Webforms.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.