2009-10-08 54 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。我不知道为什么”