Search code examples
c#asp.net.netasp.net-routing

How to get actual URL from a list of routes?


i have a set of routes defined in System.Web.Routing and in need to get the actual url's with the .aspx extension. i've tried this code but i'm doing something wrong here:

 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
 }

any idea on how i can do this? The item.link is a custom object where i have the route.


Solution

  • ok, so i found the answer :

     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
     }