Labels

Tuesday, April 28, 2009

MVC || Deployment || IIS 6.0

Deployment in IIS

 

The ASP.NET MVC framework depends on ASP.NET Routing to route browser requests to controller actions. In order to take advantage of ASP.NET Routing, you might have to perform additional configuration steps on your web server. It all depends on the version of Internet Information Services (IIS) and the request processing mode for your application.

 

Here’s a summary of the different versions of IIS:

 

  • IIS 7.0 (integrated mode) – No special configuration necessary to use ASP.NET Routing.
  • IIS 7.0 (classic mode) – You need to perform special configuration to use ASP.NET Routing.
  • IIS 6.0 or below – You need to perform special configuration to use ASP.NET Routing.

 

Here we’ll talk about IIS 6.0 deployment.

 

There are two approaches.

 

  • Extension Support
  • Non Extension Support - Wildcard Script Map

 

 

Approach 1 - Extension Support

 

Here the thought is to provide support for .mvc extension. This requires below steps.

 

  • Registers a new .mvc extension with IIS. This can be done by registering the script at “C:\Program Files\Microsoft ASP.NET\ASP.NET MVC\Scripts\ registermvc”. Or it canbe done manually as well.
  • Make a change in Global.asax to include the .mvc extension in routing.

 

 

public class MvcApplication : System.Web.HttpApplication
    {
        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 = "" }
            );
        }
 
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }

 

 

After making these modifications to your route table, you’ll need to make sure that all of the links in your application are compatible with these new URL patterns. In other words, make sure that all of your links include the .mvc extension. If you use the Html.ActionLink() helper method to generate your links, then you should not need to make any changes.

 

 

Approach 2 – Non-Extension Support - Wildcard Script Map

 

If you don’t want to modify the URLs for your ASP.NET MVC application, and you have access to your web server, then you have an additional option. You can create a wildcard script map that maps all requests to the web server to the ASP.NET framework. That way, you can use the default ASP.NET MVC route table with IIS 7.0 (in classic mode) or IIS 6.0.

 

Be aware that this option causes IIS to intercept every request made against the web server. This includes requests for images, classic ASP pages, and HTML pages. Therefore, enabling a wildcard script map to ASP.NET Does Have Performance Implications.

 

Follow these steps to create a wildcard script map with IIS 6.0:

 

  1. Right-click a website and select Properties
  2. Select the Home Directory tab
  3. Click the Configuration button
  4. Select the Mappings tab
  5. Click the Insert button (see Figure 4)
  6. Paste the path to the aspnet_isapi.dll into the Executable field (you can copy this path from the script map for .aspx files)
  7. Uncheck the checkbox labeled Verify that file exists
  8. Click the OK button

 

After making the changes confirm the Global.asax should have at least below minimum.

 

 

public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { action = "Index", id = "" }
              );
 
            routes.MapRoute(
              "Root",
              "",
              new { controller = "Home", action = "Index", id = "" }
            );
        }
 
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }

 

 

After enabling a wildcard script map for either IIS 7.0 or IIS 6.0, you can make requests that work with the default route table that look like this:

/

/Home/Index

/Product/Details/3

/Product

 

 

 

Hope this is clear now.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

No comments:

Post a Comment