lundi 2 mai 2016

Is ControllerBase.Execute(RequestContext) obsolete in MVC5?

I am upgrading a web site from MVC3 to MVC5. I simply used NuGet to install Microsoft.AspNet.Mvc version 5.2.3 and everything seemed to be working fine. But upon closer examination I noticed that this code was no longer running:

public abstract class BaseController : System.Web.Mvc.Controller
    protected override void Execute(RequestContext requestContext)

I found this lifecycle documentation (linked from here) which seems to confirm that Execute is no longer called by MVC.

However, this documentation is unclear, saying

This method is an implementation of Execute. You typically do not have to override this method. Override Initialize or ExecuteCore instead.

I would expect it to say "This method is no longer called by the MVC framework as of version 5 (or maybe 4)." Perhaps even mark it [Obsolete], although there may have been good reasons not to do that.

Furthermore, my testing shows that ExecuteCore does not get called either! It looks like OnActionExecuting is the best place to move the code that used to live in Execute, is that correct?

Aucun commentaire:

Enregistrer un commentaire