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
{
get
{
return _myData;
}
}
protected override void ExecuteCore()
{
_myData = "I am doing something";
base.ExecuteCore();
}
}
public class HomeController : BaseController
{
public ActionResult Index()
{
ViewBag.MyData = MyData;
// Doing something with value in BaseClass
return View();
}
}
Or more better add some logic in DisableAsyncSupport property which return true if action is synchronous, false otherwise.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
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>.
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?
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
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
public class HomeController : Controller
{
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
{
return base.BeginExecuteCore(callback, state);
}
Jamie Brown
Replacing ExecuteCore with it, doesn't seem to work for me.
What do you mean by doen't seem to work?
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Member
2 Points
1 Post
ExecuteCore() in base class not fired in MVC 4 beta
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.
Controller baseclass
All-Star
33953 Points
8478 Posts
MVP
Re: ExecuteCore() in base class not fired in MVC 4 beta
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,
Or more better add some logic in DisableAsyncSupport property which return true if action is synchronous, false otherwise.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Contributor
2137 Points
604 Posts
Microsoft
Re: ExecuteCore() in base class not fired in MVC 4 beta
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>.
ASP.NET Team
@marcind
Blog
None
0 Points
1 Post
Re: ExecuteCore() in base class not fired in MVC 4 beta
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?
-Trent
All-Star
33953 Points
8478 Posts
MVP
Re: ExecuteCore() in base class not fired in MVC 4 beta
May 06, 2012 06:08 AM|imran_ku07|LINK
You can use BeginExecuteCore
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Member
20 Points
50 Posts
Re: ExecuteCore() in base class not fired in MVC 4 beta
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.
All-Star
33953 Points
8478 Posts
MVP
Re: ExecuteCore() in base class not fired in MVC 4 beta
Jul 31, 2013 06:14 AM|imran_ku07|LINK
What do you mean by doen't seem to work?
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Member
20 Points
50 Posts
Re: ExecuteCore() in base class not fired in MVC 4 beta
Jul 31, 2013 06:23 AM|Jamie Brown|LINK
Thank you. I was missing the parameters.....
That works perfectly!