Click here to Skip to main content
15,886,724 members
Articles / Web Development / ASP.NET

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

Rate me:
Please Sign up or sign in to vote.
2.45/5 (6 votes)
14 Jan 2009CPOL2 min read 30.7K   15   5
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)


Written By
Architect HCL Technologies
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralLaziness Pin
Shog929-Jan-09 7:49
sitebuilderShog929-Jan-09 7:49 
GeneralMy vote of 1 Pin
codeguruj23-Jan-09 6:20
codeguruj23-Jan-09 6:20 
Generalthere is another simple way in iis6.0 Pin
Haozes14-Jan-09 18:36
Haozes14-Jan-09 18:36 
GeneralRe: there is another simple way in iis6.0 Pin
Ajit Shekhawat14-Jan-09 18:42
Ajit Shekhawat14-Jan-09 18:42 
GeneralRe: there is another simple way in iis6.0 Pin
Haozes14-Jan-09 19:13
Haozes14-Jan-09 19:13 

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

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