Monday, August 13, 2012

Deploy ASP.NET MVC App on Windows XP (IIS 5.1)

Deploying ASP.NET MVC application on Windows XP is definitely not easy; there are a lot of settings that need to be tuned. The first thing to do is to add the relevant mapping to the Application Configuration of the MVC application. To do this, one must go to Start-> Control Panel-> Administrative Tools-> Internet Information Services.

Configuring IIS

  1. Right clicking on the Virtual Application node and select Properties
  2. Go to the Virtual Directory tab and select Configuration
  3. You will see Application Configuration dialog which displays a list of ISAPI mappings. Scroll down to see if .mvc is in the list.
  4. If it is in the list on your machine, you can skip to Step 8. If it’s not in the list, let’s add it to the list.
  5. Click Add which will bring up an empty Add/Edit Application Extension Mapping dialog.
  6. Generally the path would be C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll. Check if this is correct in your case.
  7. Fill in the fields with the exact path and the extension should be .mvc .
  8. Make sure that you have specified verbs - Limit to:GET,POST,HEAD,DEBUG and Not ALL.
  9. Make sure you have unchecked "Verify that file exists" option.
  10. Click OK and you’re done with the mapping.

Configuring Routes with an Extension 

Lets update the default routes to look for the file extension we chose, whether it be .mvc or .aspx extension. Use the RegisterRoutes method in your Global.asax.cs file using the .mvc extension. If you want to use the .aspx extension, just replace {controller}.mvc with {controller}.aspx.
public static void RegisterRoutes(RouteCollection routes)
        {
            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 = "" }
            );
        }

Output URL:

Note: The URL must contain the .mvc extension.
http://localhost/sampleweb/Home.mvc/index