在我的ASP.NET MVC3应用程序中,我尝试模拟“routes.IgnoreRoute(”“...”“)”我创建了CustomMvcRouteHandler:
public class CustomMvcRouteHandler: MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// do something
....
return base.GetHttpHandler(requestContext);
}
}在我的Global.asax.cs文件中有:
protected void Application_Start()
{
// ............
RegisterRoutes(RouteTable.Routes);
// ............
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("elmah.axd");
//routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).RouteHandler = new CustomMvcRouteHandler();
}我该怎么做呢?
发布于 2011-02-16 03:15:47
我不完全确定你的问题是什么意思,但我会试着回答它。
要模拟IgnoreRoute,您只需从您的路由关联一个StopRoutingHandler实例。如果你使用的是内置的ASP.NET "Route“类,那么你应该这样做:
routes.MapRoute(
"Ignore-This", // Route name
"ignore/{this}/{pattern}" // URL with parameters
).RouteHandler = new StopRoutingHandler();匹配该模式的任何内容都将导致路由系统立即停止处理任何更多的路由。
如果您想编写自己的自定义路由(例如,从RouteBase派生的新路由类型),则需要从其GetRouteData方法返回StopRoutingHandler。
发布于 2013-09-14 17:03:23
@Eilon是正确的答案。下面是另一种感觉更像MVCish的语法。
routes.Add("Ignore-This",
new Route(
"ignore/{this}/{pattern}",
new StopRoutingHandler())
);https://stackoverflow.com/questions/4994644
复制相似问题