An Introduction to URL Routing

Please install Silverlight or click download to watch video locally.

In this tutorial, Stephen Walther demonstrates how browser requests get mapped to controller actions through URL Routing. You also learn how to create a custom route that displays different blog entries depending on the date passed in a URL. For additional information about this video, read the "An Introduction to URL Routing" tutorial (C#, VB).

Presented by Stephen Walther

Duration: 14 minutes, 42 seconds

Date: 20 August 2008

Watch    Video   |   Download    Video

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 24

Leave a Comment

cv_vikram : On August 25, 2008 7:13 PM said:

Thanks...

kumanan : On September 16, 2008 1:05 PM said:

Hi Steve,

Excellent Videos. so easy to understand. I have watched your first three videos of MVC. Got a solid understanding of model,view and controllers and various types of ActionResult, HtmlHelpers etc.

amanprogrammer : On September 16, 2008 4:10 PM said:

Stephen you rock. Nice video.

atarikg : On October 02, 2008 6:10 PM said:

I agree with kumanan..

akbar_khan : On October 24, 2008 12:18 PM said:

Excellent job Stephen, I have watched 4 of your videos so far and am planning to watch the rest over the weekend and write up my own first MVC Apps. Keep it up!

sanjayaghimire : On November 23, 2008 11:10 PM said:

Good video, but how to include virtual directory path?

Example on video is based on server root, VS2008 :if you use physical Web Server rather than VS Web Server, it will ask create virtual directory? But that does not change routing table in Global.asax file, then application failed with 404 Error.

Thanks for your information.

mbarlowm : On December 12, 2008 7:22 PM said:

if you put a bad date in the url with the archive/date example you get an error.  how can you handle this elegantly?

worldlifesite : On December 21, 2008 11:56 AM said:

If you maintain MVC code, isn't there a possibilty that you'll inherit the dreaded spaghetti code with url routing?

waleedbutt : On January 23, 2009 3:18 AM said:

very nice indeed

Yankee : On February 10, 2009 2:33 PM said:

Hello Stephen and thanks for those great tutorials!

Can you please tell me how can I use routing with data retrieved from a database?

Let's say that I have an unrouted link like:

/Default.aspx?CategoryID=22

but that category has a name, which for each ID it can be different. So I will extract that data from the database.

Simply put, I want to dynamically build those links, like WordPress' links. Each link with its - let's say - title, retreived from a database.

Thank you!

Yankee : On February 10, 2009 2:36 PM said:

Forgot to mention to my previous post, an unrouted link like

/Default.aspx?CategoryID=22 to be routed to /Categories/Cars

and

/Default.aspx?CategoryID=23 to be routed to /Categories/Trains

and so on.

Tunisiano32 : On March 03, 2009 11:13 PM said:

Very good video

Thanks

Danny117 : On March 08, 2009 6:12 PM said:

Stephen,

Thanks. I'm getting this more and more. I sure wish you would've mentioned that controler functions can't be overloaded like you did in video three. Maybe overloaded controler functions will come in a future release! I'm confident everyone watching knows they can pass in a string and fanagle it to meet their needs so its no big deal. I've watched half the introductory videos so far.

Djibril_Chimere_DIAW : On March 16, 2009 9:18 AM said:

Thanks! Jërëjëf!

Posted at 05:13 in the video

NYCharles : On April 13, 2009 6:27 PM said:
your face blocks the code
ronnieoverby : On April 16, 2009 2:53 PM said:

It sure would be nice if I didn't have to look at this guys head while I am trying to pay attention to the code.

ronnieoverby : On April 16, 2009 2:54 PM said:

It would be so nice to not have to see this guy's head.

Vishal : On May 15, 2009 7:26 AM said:

Hi Stephen,

I always wondered how this worked, now I know. :-) Is the member profile page on forums.asp.net designed in the same way? For e.g. my profile page is http://forums.asp.net/members/Vishal.aspx . So I assume this is achieved by URL Routing.

Thanks,

Michael1 : On June 28, 2009 3:48 AM said:

Stephen,

I am hitting a brick wall with these tutorials being in Visual Basic. I know nothing about Visual Basic, and am spending 20% of my time understanding the concepts, which are well presented, and 80% of my time converting the code from a language I know nothing about, Visual Basic, to C#, quite unsuccessfully I might add. The controller file looks almost nothing like that in C#. The written tutorial for C# only covers about 1/3 of the video tutorial. I could have used this material for a project I am doing. PLEASE, at a minimum provide full source code in C# for the ENTIRE video tutorial, and, better yet, provide complimentary video tutorials in C# (since they are only about 10 minutes each anyway).

Thanks.

mind1n : On July 14, 2009 1:33 PM said:

That face isn't nessary to be shown! Agree?!

milind_wmahajan : On August 25, 2009 6:05 PM said:

Stephen its really cool

kannank7 : On September 20, 2009 7:56 AM said:

stephen its really a great video for a beginner.

roman.spataru : On October 06, 2009 12:09 PM said:

Thanks Stephen!

gerrylowry : On November 19, 2009 4:33 PM said:

Resources useful for routing issues:

Routes are processed top down, first match is route used. You'll probably need the ability to debug your routes:

The first rule that fits the URL is the one that gets used. Default rules should be last.

The most general default rule should be the very last.

There's a really interesting tool and video that you might want to check out:

the RouteDebug dll tool is discussed in the last twenty minutes*

of Phil Haack's video: http://videos.visitmix.com/MIX09/T44F,

"Ninja on Fire Black Belt Tips".

* Watch the entire video, it's worth your time.

ASP.NET MVC documentation is at MSDN:

Reference http://msdn.microsoft.com/en-us/library/dd566232.aspx

Routing is here:

http://msdn.microsoft.com/en-us/library/system.web.routing.aspx

http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.aspx

see also: http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx

http://www.asp.net/learn/mvc/tutorial-23-cs.aspx

for IgnoreRoute see:

http://msdn.microsoft.com/en-us/library/dd505203.aspx in

http://msdn.microsoft.com/en-us/library/system.web.mvc.routecollectionextensions.aspx.

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities