Last post Jul 31, 2013 06:23 AM by Jamie Brown
Mar 04, 2012 07:48 AM|Martooo|LINK
I have a base controller class:
And all my other controller inherits this BaseClass like this
All this works great in MVC3 (test again today, it really works) but it seems that the ExecuteCore in BaseController is not fired any more in MVC 4 beta.
Any idea? Or Anything huge has changed under the hood? Thanks very much.
public class BaseController : Controller
private string _myData;
public string MyData
protected override void ExecuteCore()
_myData = "I am doing something";
public class HomeController : BaseController
public ActionResult Index()
ViewBag.MyData = MyData;
// Doing something with value in BaseClass
Mar 04, 2012 11:57 AM|imran_ku07|LINK
I think you are correct this is something breaking change because it will disallow ExecuteCore to run in MVC 3 applications migrated to MVC 4.
Quick Fix, add this in your base controller,
protected override bool DisableAsyncSupport
Or more better add some logic in DisableAsyncSupport property which return true if action is synchronous, false otherwise.
Mar 04, 2012 01:59 PM|marcind|LINK
That's correct. This is an intentional breaking change in the MVC 4 Beta. The ExecuteCore method is no loner being called (unless you override DisableAsyncSupport to return true, as Imran points out). This was done to support asynchronous action methods
that return Task<T>.
May 02, 2012 09:28 AM|wolfpackt99|LINK
I am attempting the same thing:
I am trying to give the ability for a user to choose their own culture. A lot of samples out there refer to override "ExecuteCore" in a Base Controller to check the presence of a cookie like _culture. Everything is wired up, the cookie is set (verified with
fiddler) however, i can't seem to get ExecuteCore to fire.
Based on the comments above i see how to force it to fire for my code to set the culture, but how to i cover scenarios where the controller is async. Should i add this logic to set the culture in a different method altogether?
May 06, 2012 06:08 AM|imran_ku07|LINK
how to i cover scenarios where the controller is async. Should i add this logic to set the culture in a different method altogether?
You can use BeginExecuteCore
Jul 31, 2013 06:02 AM|Jamie Brown|LINK
imran, how do you use the BeginExecuteCore? Replacing ExecuteCore with it, doesn't seem to work for me.
Jul 31, 2013 06:14 AM|imran_ku07|LINK
how do you use the BeginExecuteCore?
public class HomeController : Controller
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
return base.BeginExecuteCore(callback, state);
Replacing ExecuteCore with it, doesn't seem to work for me.
What do you mean by doen't seem to work?
Jul 31, 2013 06:23 AM|Jamie Brown|LINK
Thank you. I was missing the parameters.....
That works perfectly!