Using ASP.NET MVC on IIS6 or below

Posted by Tim on January 13, 2009 in .NET Framework, ASP.NET, C# |

When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change the URL routing table within the Global.asax file.

Origional file:

public class GlobalApplication : System.Web.HttpApplication
 {
 public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                routes.MapRoute(                     "Default",// Route name                     "{controller}/{action}/{id}",// URL with parameters                     new { controller = "Home", action = "Index", id = "" }                           // Parameter defaults                );
 }
 protected void Application_Start()
 {
 RegisterRoutes(RouteTable.Routes);
 }
 }

Change to the following:

public class GlobalApplication : System.Web.HttpApplication
 {
 public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                routes.MapRoute(                     "Default",// Route name                     "{controller}.aspx/{action}/{id}",// URL with parameters                     new { controller = "Home", action = "Index", id = "" }                           // Parameter defaults                );
 }
 protected void Application_Start()
 {
 RegisterRoutes(RouteTable.Routes);
 }
 }

Just add the .aspx extension so that it registers through the .NET Framework.

ALSO remember to do a Response.Redirect in the default.aspx page so that the first page will be your default URL routing page, otherwise you will receive a HttpException “The incoming request does not match any route.”.

Tags: , ,

Leave a Reply

Copyright © 2008-2012 Codelab Blog All rights reserved.
Desk Mess Mirrored version 1.9.1 theme from BuyNowShop.com.