Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all routes defined in global.asax

I am using webformrouting in my asp.net c# application.

In my global.asax file i define a couple of routes.

My question is, how can i get a list of all routes defined from code behind (on a page)?

like image 839
stoic Avatar asked Jan 28 '10 18:01

stoic


2 Answers

You can access the Routes property on the RouteTable

System.Web.Routing.RouteTable.Routes;
like image 126
Brandon Avatar answered Oct 01 '22 00:10

Brandon


I create a partialView to visualize these in the site to help me from time to time (debugging).

@{ 
    var routes = RouteTable.Routes;
}
@foreach (var route in routes)
{
    var r = (System.Web.Routing.Route)route;
    <h4>@r.Url</h4>
}
like image 35
Ryan Mann Avatar answered Oct 01 '22 00:10

Ryan Mann