Can someone explain asp.net routing syntax to me? Can someone explain asp.net routing syntax to me? asp.net asp.net

Can someone explain asp.net routing syntax to me?


My 2 cents:A route is not regex. It is simply variable and static components that make up a route, separated by segments (identified by a slash). There's one special symbol, the asterisk in the last variable, which means from here on, ignore the segment-separator -- the slash. So,

{*url} 

is the simplest route, because it means take the entire URL, put it into the variable 'url', and pass that to the page associated with that route.

{controller}/{action}/{id}

puts everything in the first segment -- up to the first slash -- into the variable 'controller', puts everything between the first and second / into the variable 'action', and everything between the second and third slash (or the end) into the variable 'id'. those variables are then passed into the associated page.

{resource}.axd/{*pathInfo}

here, put the info before .axd/ (and it can't have any slashes!) into 'resource', and put everything after the first / into 'pathInfo'. Since this is typically an ignoreRoute, so instead of passing it to the page associated, it is handled by the StopHandler, which means that routing won't deal with it, and it is instead handled by the non-routing HttpHandler.

As bleevo says, routes are executed in order they're added to the collection. so IgnoreRoute s have to be added before the generic route is handled.

Here's the horse's mouth: http://msdn.microsoft.com/en-us/library/cc668201.aspx

Specific to your example, I would put the IgnoreRoute lines above your Route addition, because your route is effectively a catch-all. Also, remember that the .gif ignore will only be honoured if the gif is in the root directory.


pathinfo is just a label for a bucket. So for instance {*pathinfo} says put everything after {resource}.axd/ into pathinfo.

The routes are executing in the order you place them in the routes table, so if your very first route is a catch all the rest will never execute.