未找到 ASP.NET MVC 资源

未找到 ASP.NET MVC 资源

我正在使用 .NET Framework 4.0 + MVC2 在 Visual Studio 2010 中开发一个 MVC 项目,如果我将目标框架设置为 .NET 4.0,一切就都正常了。但是,我的主机不提供 .NET 4.0,因此我需要在 .NET 3.5 上部署网站,才能让它正常运行。

我尝试将其转换为 ASP.NET 3.5,并且一切都构建正常,但现在当我尝试加载主页时,出现 404 错误:

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

有人知道这是为什么吗?

谢谢你的帮助。TheLorax

答案1

根据我使用 ASP.NET MVC 的经验,我发现Default.aspxIIS 需要一个页面才能正常运行。我使用的是 ASP.NET MVC 1 模板中包含的页面。不幸的是,ASP.NET MVC 2 不包含此页面(据我所知),因此您应该将以下内容添加到您的项目中:

默认.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. --%>

默认.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);
        }
    }
}

答案2

简单的解决方案:切换到 Visual Studio 2008 + SP1 + MVC 1。这是已发布/支持的组合。如果您的主机未安装 MVC 程序集,那么它们可以并排部署,您需要确保您的主机具有 .NET 3.5SP1

如果我没记错的话,VS2010 B2 包含 MVC***2*** B2,但不包括 MVC***1***。

答案3

可能是您要发布的服务器上未安装 MVC 程序集。尝试进入您的 MVC 项目,然后在资源下将所有 MVC 特定程序集的属性 copy local 更改为 true(或者只需突出显示引用下的所有内容并将此属性设置为 true)。

相关内容