Posts

Showing posts with the label Routing

Life cycle of an Asp.Net MVC request

Image
When you invoke an action in an MVC application, everything happens as if you were simply calling a method in the controller class. How do we go from a http request to a method invocation with arguments? We will try here to describe everything that happens during the MVC request processing. Routing The first system to handle the request is routing. It analyzes the request depending on the context and chooses which controller and which action has to be called. In an MVC application, the goal of routing is to create a route data dictionary containing at least 2 entries: “controller” and “action” (+ “area” if needed). Those 2 entries will allow the correct controller to be instantiated and the correct action to be called during the next steps. Routing is an http module: System.Web.Routing.UrlRoutingModule handling the cached routing results and a http handler System.Web.Routing.UrlRoutingHandler handling the request itself. It relies on the route table defined...

Most important new features in ASP.NET 4.0 - Part 2

Routing in ASP.NET 4 Although routing features comes with ASP.NET 3.5, ASP.NET 4 comes with new additions to make it easier to use the routing mechanisms, such as: The PageRouteHandler class, which is a simple HTTP handler that you use when you define routes. The class passes data to the page that the request is routed to. The new properties HttpRequest.RequestContext and Page.RouteData (which is a shortcut to HttpRequest.RequestContext.RouteData). These properties make it easier to access information that is passed from the route. The following new expression builders, which are defined in System.Web.Compilation.RouteUrlExpressionBuilder and System.Web.Compilation.RouteValueExpressionBuilder:  RouteUrl , which provides a simple way to create a URL that corresponds to a route URL within an ASP.NET server control. RouteValue , which provides a simple way to extract information from the RouteContext object. ...