Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does IIS server identify that request is mvc request?

In asp.net life cycle, on basis of the extension (.aspx), the request would be identified and handled by aspnet_isapi.dll and then httpapplication object is created followed by request and response objects and then request is processed by ProcessRequest() method.

I was going through mvc page life cycle

I have doubt about how the IIS server is able to identify the incoming request is MVC request?

like image 453
Mrudang Vora Avatar asked Aug 05 '14 08:08

Mrudang Vora


People also ask

How IIS process ASP.NET MVC request?

In asp.net life cycle, on basis of the extension (. aspx) , the request would be identified and handled by aspnet_isapi. dll and then httpapplication object is created followed by request and response objects and then request is processed by ProcessRequest() method.

How does IIS process the request?

IIS has its own ASP.NET Process Engine to handle the ASP.NET request. So, when a request comes from client to server, IIS takes that request and process it and send the response back to clients. Hope, till now it's clear to you that what is the Web server and IIS is and what is the use of them.


3 Answers

Both the answers with some research I did, collectively resolves my question.

Step 1: From the below mentioned article #1 (which I found during my research):

From a very high view, IIS is just a process which is listening on a particular port (usually 80). Listening means it is ready to accept a connections from clients on port 80. A very important thing to remember is: IIS is not ASP.NET. This means that IIS doesn't know anything about ASP.NET; it can work by itself.

Step 2:

Note: When we deploy and start the application in IIS, it would call Application_Start which would register the routes. So, when MVC request comes to IIS, we are ready with our Route Table to handle this request.

Step 3:

As mentioned by @Babin, IIS doesn't know how to handle the request but because of ASP.NET framework, the request automatically goes to managed handlers.

Step 4:

As mentioned by @Rune, the request is intercepted by the UrlRoutingModule which in turn gets object of MvcRouteHandler class that will ultimately map to controller and action to handle the request.

Step 5:

As mentioned in one of SO question's comments:

If no routes match, the UrlRoutingModule object does nothing 
and lets the request fall back to the regular ASP.NET or IIS request processing.

References:

I found good articles to read through and clear out the doubts in IIS request processing.

1) The following link has in-depth explanation for how IIS handles ASP.NET WebForms request: http://www.codeproject.com/Articles/121096/Web-Server-and-ASP-NET-Application-Life-Cycle-in-D

2) The following links explains how IIS handles MVC requests using managed handlers: http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx

3) MVC Lifecycle: http://pratiktips.blogspot.de/2012/08/the-magic-of-aspnet-mvc-model-binding.html

like image 195
Mrudang Vora Avatar answered Sep 26 '22 04:09

Mrudang Vora


IIS 7+ can run in two pipeline modes: "Classic mode" and "Integrated mode". The latter mode means that ASP.NET sees all incoming requests and can handle / manipulate them.

If you are asking how ASP.NET knows to invoke MVC, that is described in step 4 of the diagram you linked to: The UrlRoutingModule matches the request against all registered routes. When using MVC, you will have registered a route with a MvcRouteHandler. From MSDN:

A MvcRouteHandler instance is registered with routing when you use the MapRoute method. When the MvcRouteHandler class is invoked, the class generates an MvcHandler instance using the current RequestContext instance. It then delegates control to the new MvcHandler instance

like image 41
Rune Avatar answered Sep 25 '22 04:09

Rune


IIS doesn't know; ASP.NET knows via HTTP Handlers

Both WebForms and MVC are built on top of ASP.NET, and both use HTTP Handlers to deal with per-request execution:

  • WebForms has .aspx files mapped to the PageHandlerFactory: PageHandlerFactory implements IHttpHandlerFactory::GetHandler() returns HttpHandler

  • MVC integrates into the Routing infrastructure as an IRouteHandler implementation. Routes is notified of requests via the UrlRoutingHandler URLRoutingHanlder implements IHttpHandler. ASP.NET MVC is just a custom handler added to the ASP.NET pipeline.

Below is MVC 4.0 & ASP.NET 4.0 onwards These rules can be defined at any level in IIS. Most MVC applications define the handlers at the application level in the web.config file

<handler>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0"/>
</handlers>
like image 29
Babin Avatar answered Sep 25 '22 04:09

Babin