我有一组在System.Web.Routing中定义的路由,需要获取带有.aspx扩展名的实际url。我试过这段代码,但我在这里做错了什么:
var path = RouteTable.Routes.GetVirtualPath(null, item.Link, null);
var link = path.Route.GetVirtualPath(null, null);
if (link.VirtualPath.ToLower().Contains("~/displaycmspage.aspx?pagename="))
{
//do work on url here
}
关于我如何做到这一点的任何想法? item.link是一个自定义对象,我有路径。
答案 0 :(得分:1)
var path = RouteTable.Routes[item.Link];
Route ruta = path as Route;
var link = ruta.RouteHandler as PageRouteHandler;
if (link.VirtualPath.ToString().ToLower().Contains("~/displaycmspage.aspx?pagename="))
{
//do work on url here
}