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 CPOL
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)

Share

About the Author

Ajit Shekhawat
Architect HCL Technologies
India India
No Biography provided

Comments and Discussions

 
GeneralLaziness PinsitebuilderShog929-Jan-09 8:49 
While i applaud your desire to share solutions to some problems you've encountered, i must disagree with the way in which you've done so. You fail to describe the problems in detail, and provide even less information regarding the mechanism by which your solutions/work-arounds accomplish their goals.
 
Given that ASP.NET MVC is still in beta, the way such problems manifest themselves is likely to change over time, as are the work-arounds for them. Without sufficient information, this article has little chance of being useful now and even less chance of remaining useful in the near future.
 
The sad part of this is you likely knew it when you wrote it. The article you link to provides better descriptions of both the problem and solutions, meaning you've essentially make a bad resource out of a good one in writing this article.
 
Before posting another, i suggest you look at your source material and ask yourself: if someone came to me for help, would i send him a link to my article, or the articles i based it on? If the latter, don't bother submitting your article at all.
 

GeneralMy vote of 1 Pinmembercodeguruj23-Jan-09 7:20 
Generalthere is another simple way in iis6.0 PinmemberHaozes14-Jan-09 19:36 
GeneralRe: there is another simple way in iis6.0 PinmemberAjit Shekhawat14-Jan-09 19:42 
GeneralRe: there is another simple way in iis6.0 PinmemberHaozes14-Jan-09 20: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 | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 14 Jan 2009
Article Copyright 2009 by Ajit Shekhawat
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid