2009-10-08 96 views
0

這裏的錯誤:ASP.NET MVC 2預覽2路由請求不工作

The incoming request does not match any route. 

基本上我從第一個預覽版升級到第二個預覽版,並擺脫了相對冗餘的東西負載的地區(如描述由菲爾Haack)。它沒有工作,所以我創建了一個全新的項目,檢查出其是如何在預覽2.文件Default.aspx不再存在,包含以下處理:

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

我收到點到線httpHandler.ProcessRequest(HttpContext.Current);錯誤但在較新的項目中,這些都不存在。爲了測試它,我很快刪除了Default.aspx,但完全沒有任何工作,我甚至沒有收到任何錯誤。下面是一些代碼提取物:

的Global.asax.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Routing; 

namespace Intranet 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     AreaRegistration.RegisterAllAreas(); 

     routes.MapRoute(
     "Default", 
     "{controller}/{action}/{id}", 
     new { controller = "Home", action = "Index", id = "" } 
    ); 
    } 

    protected void App_Start() 
    { 
     RegisterRoutes(RouteTable.Routes); 
    } 
    } 
} 

通知區域登記爲這就是我使用的是什麼。

Routes.cs

using System.Web.Mvc; 

namespace Intranet.Areas.Accounts 
{ 
    public class Routes : AreaRegistration 
    { 
    public override string AreaName 
    { 
     get { return "Accounts"; } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute("Accounts_Default", "Accounts/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }); 
    } 
    } 
} 

檢查有關此部分的詳細信息的最新文檔。這是註冊該地區。 Routes.cs文件位於每個區域的根文件夾中。

乾杯

+0

對不起,我是由例如工作,你打算使用'Application_Start'而不是'App_Start'。我不知道爲什麼。 – Kezzer 2009-10-08 09:07:35

+0

Application_start將被ASP.NET自動連接起來。在此頁面中搜索:http://msdn.microsoft.com/en-us/library/ms178473.aspx – 2009-10-08 14:05:21

回答

0

按照評論「對不起,我是由示例工作,你打算使用的Application_Start不App_Start。我不知道爲什麼」