【问题标题】:error running asp.net mvc 2 project out of the box in vs 2010在 vs 2010 中运行 asp.net mvc 2 项目时出错
【发布时间】:2010-12-08 17:28:29
【问题描述】:

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

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

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

【问题讨论】:

  • 这只是你用 VS 创建的一个“默认”项目,然后按 F5 吗?或者你有没有先修改任何东西。另外,您在收到此 404 错误时尝试访问的 URL 是什么?
  • @oo 我添加了一个答案,你可以试试吗?
  • 能否发布您的 Global.asax.cs 文件的内容,以防您的路线出现问题?

标签: asp.net-mvc visual-studio-2010 asp.net-mvc-2


【解决方案1】:

尝试添加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);
        }
    }
}

【讨论】:

    【解决方案2】:

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

    如果您添加并运行“开箱即用”的新 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 的操作。

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多