ASP.NET MVC Resource not found

.net-4.0asp.net-mvciis-7.5

I am working on an MVC project in Visual Studio 2010 with .NET Framework 4.0 + MVC2 and everything works if I set the target framework to .NET 4.0. However, my host does not offer .NET 4.0 in order to deploy the site I need to get it working on .NET 3.5.

I tried converting it to ASP.NET 3.5 and everything builds just fine except now when I try to load the homepage, I get a 404 Error saying:

The resource cannot be found.

 Description: HTTP 404. The resource you are looking for (or one of its dependencies)      could have been removed, had its name changed, or is temporarily unavailable.  Please      review the following URL and make sure that it is spelled correctly. 

 Requested URL: /home

 Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET  
 Version:2.0.50727.4927

Anyone know why this is?

Thank You for Your help.
TheLorax

Best Answer

From my experience with ASP.NET MVC, I've seen that a Default.aspx page is required for IIS to function correctly. I'm using the page that was included in the ASP.NET MVC 1 template. Unfortunately, the ASP.NET MVC 2 does not include this page (to the best of my knowledge), so you should add the following to your project:

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace._Default" %>

<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>

Default.aspx.cs:

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace YourNamespace
{
    public partial class _Default : Page
    {
        public void Page_Load(object sender, System.EventArgs e)
        {
            // Change the current path so that the Routing handler can correctly interpret
            // the request, then restore the original path so that the OutputCache module
            // can correctly process the response (if caching is enabled).

            string originalPath = Request.Path;
            HttpContext.Current.RewritePath(Request.ApplicationPath, false);
            IHttpHandler httpHandler = new MvcHttpHandler();
            httpHandler.ProcessRequest(HttpContext.Current);
            HttpContext.Current.RewritePath(originalPath, false);
        }
    }
}