Archive

Archive for June, 2013

ExecuteCore not called in ASP.NET MVC 4

June 13, 2013 Leave a comment

If you want a function to be called before every page load in an MVC asp.net web application, then you could of course call that function from every action, or you can override the ExecuteCore method.

But no… It never gets called, what can you do?, well, I discovered on StackOverflow, that if you also override¬†DisableAsyncSupport and return true, then the ExecuteCore method gets called

 

 

protected override void ExecuteCore()
{
// Modify current thread’s cultures
var strCulture = CurrentLocale();
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(strCulture);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

base.ExecuteCore();
}

/// <summary>
/// Ensures that ExecuteCore() is called.
/// </summary>
protected override bool DisableAsyncSupport
{
get { return true; }
}

This is how, I’ve created two code-identical sites, www.freesms.cat and www.kostenfreiesms.com with different resource files to handle two different locales

Advertisements
Categories: Uncategorized