URL mapping in .NET website

In a WebForms .NET website, is there a way to store the URL structure on one place and let some class determine URLs?

I currently have this:

NextCar.NavigateUrl = "~/Car.aspx?id=" + carId + "&page=" + (PageId + 1);

But I would prefer something like this:

NextCar.NavigateUrl = SiteMap.CurrentUrl.Set('page', PageId + 1);

or

NextCar.NavigateUrl = SiteMap.CarUrl(carId, PageId)

This way, I can store my URLs on one place and also generate a menu or sitemap automatically.

Answers


The closest equivalent to this is ASP.NET routing. It's best used with URLs of the format /Car/{carId}/{pageId} but it can be persuaded to work with query parameters if you really need them (basically, if you create a path with an unrecognised route value then it will add it to the querystring). The MSDN article "Walkthrough: Using ASP.NET Routing in a Web Forms Application" at http://msdn.microsoft.com/en-us/library/dd329551.aspx is a good starting point.


Need Your Help

Rails app slowed down after introducing database_cleaner gem

ruby-on-rails gem

I am working on a rails 3 app. Recently I have introduced database_cleaner gem. Since then, the app is extremely slow. Starting the server takes around 20 seconds. Is there something I need to do t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.