10-4 Episode 11: Bi-Directional Routing with ASP.NET WebForms 4.0

Play 10-4 Episode 11: Bi-Directional Routing with ASP.NET WebForms 4.0
Sign in to queue


In this episode of 10-4, we introduce another new feature of ASP.NET WebForms 4.0: Routing. The ASP.NET Routing engine was added in the .NET Framework 3.5 SP1 release and is heavily leveraged by both ASP.NET MVC and ASP.NET Dynamic Data to provide bi-directional routing functionality. With the release of ASP.NET WebForms 4.0, you can take full advantage of the common route engine that allows you to customize the URLs that your application exposes. In addition, new expression builders allow you to generate dynamic URLs that are based on your route definitions, alleviating you from having to hard code static links.

For more 10-4 episodes, be sure to visit:

Visual Studio Topic Area on Channel 9:

Visual Studio 2010 CTP VPC:

ASP.NET Routing:

10-4! Over and out!



Download this episode

The Discussion

  • User profile image
    That is great! Will it be possible to have declarative syntax of it? For example in web.routing file?
    JC can you tell about changes of App_Theme? I wrote about it on connect but no answer.
  • User profile image

    And about new rendering mode of controls.
    Thank you.

  • User profile image

    Very well implemented very useful feature!
    One question: what about urls localization?
    Should I populate the RouteTable by hand for every languages or there is some resource related stuffs in the API?

  • User profile image
    That is one of the first questions that always comes up after seeing ASP.NET Routing Smiley As of right now the only way to configure your routes is through code. That said, I'm a firm believer that a good API is the perfect foundation for layering additional forms of expression (i.e. loading routes from a config file or DB). There are a couple prototypes floating around that pull your route definitions from config that I'd be more than happy to share with you.

    As far as new rendering of controls, I'll deifnitely try to fit this in later episodes. Funny enough I actually showed off a very subtle change to the ListView control in this episode but I didn't call it out. You no longer have to have a PlaceHolderTemplate if your ItemTemplate's contents are truly seperate markup (i.e. not <li>'s within a <ul> for instance).

    Feel free to email me (joncart at microsoft dot com) and I can share some additional info in the meantine.
  • User profile image

    Thank you JC! I wrote you some ideas a month ago.

  • User profile image

    Do the new route tools help in moving from a site with identity keys (int) to text values. 


    I guess it would be difficult to map all the number / string pairs as routes in a config file.  I assume they could be added programatically on application start.  They would have to be recreated if something was later added to the database?

    Or do you suggest moving away from passing the primary keys of database related objects and instead passing a unique string?

  • User profile image
    I would go with the unique string approach. Since part of the whole objective is to provide more meaningful URLs to end users, integer/guid identifiers don't really provide them any value. That doesn't mean that you won't still need to do something along the lines of "Products/1" in situations were that makes sense. You might have resources that don't legitimately have a unique value other than an ID. For SEO purposes having a descriptive value in the URL certainly helps as well. "Products/Cups" is capable of being spidered as a resource on "cups" whereas "Products/45" isn't. Will that make a huge difference? Maybe not, but every little bit helps Smiley

    There is no need to get religious on either approach, it all just comes down to which approach serves the needs of your application the best. Since routing is so extensible, you should have fun building the sitemap you want. There is soooo much more to it then what I showed in this demo since this episode was meant only to show how routing and webforms can work together. General purpose routing has plenty of awesome little features.

    I doubt there will be a 10-4 episode on ASP.NET Routing specifically since it isn't a feature in .NET Framework 4.0, but I could throw together some ad-hoc screencasts and plop them on my blog (http://www.lostintangent.com) or C9.

    Keep these great questions coming guys, I seriously love the 10-4 community Smiley
  • User profile image
    3:05am to 8:41am

    thats fast Tongue Out
  • User profile image

    Great to hear!

  • User profile image

    Is there a source file included with demo?


    I have been trying to run this and keep getting file not found error I am using VS2010 Beta 2

Add Your 2 Cents