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

后端 未结 3 998
既然无缘
既然无缘 2021-01-18 21:50

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:

3条回答
  •  一个人的身影
    2021-01-18 22:43

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

提交回复
热议问题