TechEd Barcelona – Day 2 – ASP.NET MVC Practices

Written by Yves

November 12, 2008

<Disclaimer>This is personal notes of what I retained during the session. This can be incomplete, partially right or wrong. It is just  part of the notes I took and what retained my attention. Nothing prevents the user to get more information on their favorite web site.</Disclaimer>


Hadi Hariri started by explaining that the ASP.NET MVC framework is based on the routing mechanism that has been part of the ASP.NET frameword itself since the beginning, meaning that it is available for webforms development as well. The only thing is that the ASP.NET MVC framework relies on the MvcHttpHandler class. Basically, routing are declared in the Global.asax file ordered from the more restrictive routing first to the generic one. Like we do for exception catching, meaning that if the most generic routing is declared first, this will be the only one that will be used. Routing can use constraints, such as regular expression or even on custom classes, implementing the Match method. Then, during the first demo, Hadi shows us hot to define routes using constraints and how to debug such routing. One of his advice is to always test routing. Indeed, most of the issues are coming from wrong route declaration.
On the Controllers side, the MvcHttpHandler instanciates a ControllerFactory which in turn instantiates the right controller using reflection. Reflection can be a performance killer, but in this case, the controllers are stored in the ControllerTypeCache, avoiding to make the use of the reflection everytime. Following this explanation, a demo using the Unity IoC container is showed.
Actions find the right method, bind parameters and execute the actions. Filter pipeline can be used : IAuthorizationFilter calls IActionFilter which in turn calls IResultFilter. On its side, HttpAuth delegates the authentication to another class.
About the view engine, its only role is to look for a view. It is not of its responsability to render the result.
When using the ASP.NET MVC framework, standard ASP.NET user controls can be used, but only in read-only.

You May Also Like…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *