ASP.NET MVC Framework and IIS: What's the connection?

Posted: Feb 11, 2010  8 comments  

Average Rating

Tags
ASP.NET
IIS 6
IIS 7
MVC

Share this Post

"Can you tell me as to how ASP.NET MVC is processed in IIS?" I came across this interesting question from a member of my audience when I was giving a session for Community Techdays a few days back. I am not much of an ASP.NET developer therefore as much as I would hate to I had to say "Let me get back to you later on that".

So here's what I have figured out so far:

ASP.Net MVC or ASP.Net Model View Controller was introduced with .Net 3.5. The basic difference between an ASP.Net application and and ASP.Net MVC is that in ASP.Net, traditionally, the .Net framework maps the URL to a certain file on the disk (This file on disk has the code, that performs certain logic and also the markup to which is then sent to the requestor), whereas in ASP.NET MVC the URL is mapped to a controller where the controller class is responsible for handling various features of the request.

The mapping of these ASP.NET MVC URL's is handled by the ASP.NET routing engine. I am not going to go into how the MVC is executed. But for further details you can check this.

Lets look at it from an IIS perspective now. ASP.NET is executed in different ways in different versions of IIS. I will be covering IIS 6, IIS 7 and IIS 7 ... Yes I mention IIS 7 twice ... :) the 1st one is for IIS 7 with Integrated Pipeline mode and the 2nd one is for IIS 7 in Classic Mode. To know more IIS 7 processing features check my previous articles IIS : Changes from 6 to 7, IIS 6 and IIS 7 - How different are they?

In IIS 6 and IIS 7 Classic Mode, ASP.NET processing is not built-in with IIS. In very simple terms when IIS determines that the request is for ASP.NET, the request is mapped to aspnet_isapi.dll and from this point on the request is executed and the response is sent back. Therefore, an extension has a lot of importance in terms of IIS 6. Hence, for ASP.NET MVC applications to work we need to have a mechanism to map the ASP.NET MVC URL's to the aspnet_isapi.dll. This is acheived in one of the two ways mentioned below:

1.) Create a wildcard mapping for the ASP.NET MVC Application website in the way shown below:

(i) Right-click on the concerning website --> select Properties
(ii) Select the Home Directory tab
(iii) Click the Configuration button
(iv) Select the Mappings tab
(v) Click the Insert button
(vi) Give the path to the aspnet_isapi.dll in the Executable field. It's under C:\Windows\Microsoft.NET\Framework\v2.0.50727\, C:\ being your System Drive.
(vii) Uncheck the checkbox labeled Verify that file exists
(viii) Click the OK button

Note: If you see the configuration tab to be greyed out, that means your application is not mapped to an Application Pool. Click on the Create button just above it and in the drop down below select an appropriate application pool.
After this is done you need to make an addition in the global.asax file in your application as below:
routes.MapRoute("Root", "", new { controller = "Home", action = "Index", id = "" });
2.) The second method is to register the .mvc extension using registermvc.wsf with IIS from the following directory, C:\Program Files\Microsoft ASP.NET\ASP.NET MVC\Scripts
Once that is done, modify you RegisterRoutes function in global.asax as follows:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Default", "{controller}.mvc/{action}/{id}", new { action = "Index", id = "" });
routes.MapRoute("Root", "", new { controller = "Home", action = "Index", id = "" } );

Now your URL's should be as follows:
{controller}.mvc/{action}/{id}
 /product.mvc/


Hope this helps.

Read the complete post here

Submit a Comment

  • Plain text is accepted.
  • URLs starting with http:// are converted to links.