作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 ASP.NET MVC3 应用程序中,我尝试模拟“routes.IgnoreRoute("...")”
我创建 CustomMvcRouteHandler:
public class CustomMvcRouteHandler: MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// do something
....
return base.GetHttpHandler(requestContext);
}
}
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();
}
最佳答案
我不完全确定您在问题中的意思,但我会尽力回答...
模拟 IgnoreRoute
您需要做的就是关联 StopRoutingHandler
的一个实例从你的路线。如果您使用内置的 ASP.NET“路由”类,那么您将执行以下操作:
routes.MapRoute(
"Ignore-This", // Route name
"ignore/{this}/{pattern}" // URL with parameters
).RouteHandler = new StopRoutingHandler();
RouteBase
的新路由类型),则来自其
GetRouteData
您需要返回
StopRoutingHandler
的方法.
关于asp.net - 如何在我的自定义 MvcRouteHandler 中模拟 IgnoreRoute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4994644/
我是一名优秀的程序员,十分优秀!