error running asp.net mvc 2 project out of the box in vs 2010

那年仲夏 提交于 2019-12-01 18:08:39

问题


i created a new solution and it builds fine targeting framework 4.0 but when i run it, my browser comes up 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: /

any ideas on how to debug this?


回答1:


Try adding the default.aspx page that comes with the asp.net mvc 1.0 project template. I had a similar issue running mvc 2 out of the box on a computer with IIS 5 (XP), and that did the trick.

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);
        }
    }
}



回答2:


You don't need to add the default.aspx page described above.

The browser will display this 404 message if you add and run a new Empty ASP.NET MVC 2 application "out of the box".

This is because of the default route that is defined in global.asax.

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

You can see it is looking for a controller called Home and an action called Index.

When creating a new empty project it's left to you to create the Home controller and Index action (they are not there in an empty project), then create the view for the Index action too.




回答3:


My guess is that you need to reregister or enable the framework under IIS. Try running aspnet_regiis from the appropriate framework tree and / or make sure that the proper framework version is allowed under IIS web extensions.



来源:https://stackoverflow.com/questions/1600961/error-running-asp-net-mvc-2-project-out-of-the-box-in-vs-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!