如何路由在asp.net MVC 3项目中的.aspx页面中? [英] How to route a .aspx page in asp.net mvc 3 project?
本文介绍了如何路由在asp.net MVC 3项目中的.aspx页面中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.aspx页以下路径:
I have a .aspx page in the following path:
Areas/Management/Views/Ticket/Report.aspx
我要路由到我的浏览器以下路径:
I want to route that to the following path in my browser:
http://localhost/Reports/Tickets
我怎样才能做到这一点?
How can i do that?
我试试这个:
routes.MapRoute(
"Tickets", // Route name
"Areas/Management/Views/Ticket/Report.aspx", // Original URL
new { controller = "Reports", action = "Tickets" } // New URL
);
但我得到了 404
错误。
我在做什么错了?
观测:我把该默认
路线之前
推荐答案
解决了!所以,我们需要一个路由约束实现添加到Web表单的路线,以确保它仅捕获传入的路线,不出局路由的产生。
Solved! So, we need to add a route contraint to the webforms route to ensure that it only catches on incoming routes, not outgoing route generation.
下面的类添加到项目中(无论是在一个新的文件或的global.asax.cs的底部):
Add the following class to your project (either in a new file or the bottom of global.asax.cs):
public class MyCustomConstaint : IRouteConstraint{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){
return routeDirection == RouteDirection.IncomingRequest;
}
}
然后,门票路径更改为以下:
Then change the Tickets route to the following:
routes.MapPageRoute(
"Tickets",
"Reports/Tickets",
"~/WebForms/Reports/Tickets.aspx",
true, null,
new RouteValueDictionary { { "outgoing", new MyCustomConstaint() } }
);
这篇关于如何路由在asp.net MVC 3项目中的.aspx页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文