Reputation: 75679
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.
Upvotes: 1
Views: 476
Reputation: 4384
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.
Upvotes: 1