How does IIS server identify that the request is an mvc request?

In the lifecycle of asp.net, based on the extension (.aspx)

, the request will be identified and processed aspnet_isapi.dll

and then an object is created httpapplication

, followed by the request and response objects, and then the request is processed ProcessRequest()

.

I survived the mvc lifecycle

I have doubts as to how the IIS server can identify the incoming request is an MVC request?

+3


source to share


3 answers


Both answers, with some research I've done, collectively solve my question.

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

From a very high level, IIS is simply a process listening on a specific port (usually 80). Hearing means that it is ready to accept connections from clients on port 80. Very important to remember: IIS is not ASP.NET. This means that IIS does not know anything about ASP.NET; it can work on its own.

Step 2:

Note: When we deploy and start the application in IIS, it would call Application_Start which would register the routes

. So when an MVC request arrives in IIS, we are ready with our route table to process that request.

Step 3:

As @Babin mentioned, IIS doesn't know how to handle the request, but due to the ASP.NET framework, the request will automatically go to the managed handlers.

Step 4:

As @Rune mentioned, the request is intercepted UrlRoutingModule

, which in turn receives an object of the MvcRouteHandler class, which will ultimately render the controller and action to handle the request.



Step 5:

As mentioned in one of the SO question 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.

      

Literature:

I found good articles for reading and clearing up IIS request handling doubts.

1) The following link provides a detailed explanation of how IIS handles an ASP.NET WebForms request: http://www.codeproject.com/Articles/121096/Web-Server-and-ASP-NET-Application-Life-Cycle-in- D

2) The following links explain how IIS handles MVC requests with 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

+2


source


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

If you are asking how ASP.NET knows how to invoke MVC, this is described in step 4 of the diagram you linked to: UrlRoutingModule

matches the request across all registered routes. When using MVC, you will register a route with MvcRouteHandler . From MSDN:



An MvcRouteHandler instance is registered with routing when using the MapRoute. When the MvcRouteHandler class is called, the class generates an MvcHandler instance using the current RequestContext instance. It then delegates control to the new MvcHandler instance

+2


source


IIS doesn't know; ASP.NET knows through HTTP handlers

Both WebForms and MVC are built on top of ASP.NET, and both use HTTP handlers to handle each request:

  • WebForms has .aspx files associated with PageHandlerFactory file: PageHandlerFactory implements IHttpHandlerFactory :: GetHandler () returns HttpHandler

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

Following are MVC 4.0 and ASP.NET 4.0. These rules can be defined at any level in IIS. Most MVC applications define application-level handlers 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>

      

+1


source







All Articles