5

我创建了一个新的解决方案,它构建了精细的目标框架 4.0,但是当我运行它时,我的浏览器出现说:

无法找到该资源。说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。请求的网址:/

关于如何调试的任何想法?

4

3 回答 3

5

尝试添加 asp.net mvc 1.0 项目模板附带的 default.aspx 页面。我在装有 IIS 5 (XP) 的计算机上开箱即用地运行 mvc 2 时遇到了类似的问题,这就是诀窍。

默认.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace.Website.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.Website
{
    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);
        }
    }
}
于 2009-11-25T04:56:46.083 回答
2

您不需要添加上述 default.aspx 页面。

如果您“开箱即用”添加并运行新的Empty ASP.NET MVC 2 应用程序,浏览器将显示此 404 消息。

这是因为 global.asax 中定义的默认路由。

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

您可以看到它正在寻找一个名为 Home 的控制器和一个名为 Index 的操作。

创建新的项目时,您需要创建 Home 控制器和 Index 操作(它们不在空项目中),然后也为 Index 操作创建视图。

于 2010-11-17T12:07:12.277 回答
0

我的猜测是您需要在IIS下重新注册或启用框架。尝试从相应的框架树运行 aspnet_regiis 和/或确保在 IIS Web 扩展下允许正确的框架版本。

于 2009-12-01T20:28:09.353 回答