2009-10-21 95 views
5

项目开箱我创建了一个新的解决方案,它建立精细瞄准框架4.0,但是当我运行它,我的浏览器出现说:错误运行asp.net的MVC 2 VS 2010

资源不能被发现。 描述:HTTP 404.您正在查找的资源(或其某个依赖项)可能已被删除,名称已更改或暂时不可用。请检查以下网址并确保它拼写正确。 请求的网址:/

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

+0

这仅仅是一个你用VS创建的“默认”项目,只是碰到F5?或者你是否先修改任何东西。另外,当你得到这个404错误时,你试图访问的URL是什么? – 2009-11-25 04:01:10

+1

@oo我添加了一个答案,你可以试试吗? – MariangeMarcano 2009-11-27 17:14:07

+0

这是MVC2测试版吗? – LiamB 2009-12-01 15:08:00

回答

5

尝试添加asp.net mvc 1.0项目模板附带的default.aspx页面。我在运行IIS 5(XP)的计算机上运行mvc 2时遇到了类似的问题,而且这样做的确有用。

的Default.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. --%> 

Default.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); 
     } 
    } 
} 
0

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

2

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

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

这是因为在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的操作。

当创建一个新的项目它留给你创建家庭控制器和索引操作(它们不存在在一个空的项目),然后创建索引操作的观点了。

+0

是的,这是正确的答案! – 2011-01-02 05:42:23