Click here to Skip to main content
Click here to Skip to main content

Running a ASP.NET MVC Beta site on IIS 5.1 and 6

, 14 Jan 2009
Rate this:
Please Sign up or sign in to vote.
Running a ASP.NET MVC Beta site on IIS 5.1 and 6

Running a ASP.NET MVC Beta site on IIS 5.1 and 6

Background

During the development of site on ASP.NET MVC I have faced some issues, which is related to IIS (6 and 5.1). I have Windows XP on my development box and Windows 2003 on my production server. I want to use my local IIS during the development and also want to deploy my site on remote server without any modification in codes.

Issue

If we create a new project in VS 2008 with ASP.NET MVC Beta and host this template site on IIS (6 or 5.1) then after opening site in browser will get following output.

Issue 1: Design is not applied on root (home) page

Home page does not use css and other formatting, Images. Home page will become:

image001.png

Issue 2: Call to controller fails and "The page cannot be found" error thrown by IIS.

And if we click on any link, which is actually a call of controller the “The page cannot be found” error thrown by IIS.

image003.png

Here is the solution for this issue (http://go.microsoft.com/?LinkId=9394801) One method is suggested to append “.aspx” in controller. Also other methods are provided there but I am not interested in them. Adding “.aspx” in controller will resolve the problem but it will not handle root url issue (Issue 1).

Resolution

Resolution 1:

Open Default.aspx.cs of root folder in your project. Modify the Page_Load function as per given below. Added codes are formatted Bold.

public void Page_Load(object sender, System.EventArgs e)
{
   if (Request.ApplicationPath == "")
   {
      HttpContext.Current.RewritePath(Request.ApplicationPath + "home.aspx");
   }
   else if (Request.ApplicationPath == HostingEnvironment.ApplicationVirtualPath) 
   {
      HttpContext.Current.RewritePath(Request.ApplicationPath + "/home.aspx");
   } 
   else 
   { 
      HttpContext.Current.RewritePath(Request.ApplicationPath);
   } 
  IHttpHandler httpHandler = new MvcHttpHandler();
  httpHandler.ProcessRequest(HttpContext.Current);
}

Now application must be working fine on IIS 5.1 and IIS 6 without facing issue 1.

Resolution 2:

To resolve issue# 2, we need to open Global.aspx.cs file and modify RegisterRoutes function. Added codes are formatted Bold.

public static void RegisterRoutes(RouteCollection routes)
{
   routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
   routes.MapRoute("Default", "{controller}.aspx/{action}/{id}", 
   new { controller = "Home", action = "Index", id = "" });
}

Now application must be working fine on IIS 5.1 and IIS 6 without facing issue 2. But addition of ".aspx" in controller will be displayed in url.

Thanks and Regards,
Ajit

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ajit Shekhawat
Architect HCL Technologies
India India
No Biography provided

Comments and Discussions

 
GeneralLaziness PinsitebuilderShog929-Jan-09 7:49 
GeneralMy vote of 1 Pinmembercodeguruj23-Jan-09 6:20 
Generalthere is another simple way in iis6.0 PinmemberHaozes14-Jan-09 18:36 
GeneralRe: there is another simple way in iis6.0 PinmemberAjit Shekhawat14-Jan-09 18:42 
GeneralRe: there is another simple way in iis6.0 PinmemberHaozes14-Jan-09 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 14 Jan 2009
Article Copyright 2009 by Ajit Shekhawat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid