[英]ASP.NET MVC 2 Preview 2 Route Request Not Working
这是错误:
The incoming request does not match any route.
基本上,我从预览版1升级到预览版2,摆脱了与区域相关的大量冗余内容(如Phil Haack所述)。 它没有用,所以我创建了一个全新的项目来检查其在Preview 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);
行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文件位于每个区域的根文件夹中。
干杯
按照评论“对不起,我正在处理此示例,您应使用Application_Start而不是App_Start。我不知道为什么”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.