[RESOLVED] url routing with asp.net 3.5 or 4

Hi I need to fix url routing different from the basics that is builtin in the framework...Basically I need it to go unlimited levels deep the same as the product catalog can when using the parent relation for each category added.

does anyone have a good sample for webforms of how I could do it...I want URL listings to look like this

www.mydomain.com/category/category2/category3/ or like this www.mydomain.com/category/category2/category3.aspx

and details URL looking like this

www.mydomain.com/category/category2/category3/title-of-article-or-productname.aspx

 

Thanks,

 

I don't know about version 3.5 but in 4.0 this should be okay.

I would just use the standard ASP.NET 4.0 routing and implement them like this:

routes.MapPageRoute("", "/Category/{cat2}", "~/Category.aspx");

<div>

routes.MapPageRoute("", "/Category/{cat2}/{cat3}", "~/Category.aspx");

</div><div>

routes.MapPageRoute("", "/Category/{cat2}/{cat3}/{cat4}", "~/Category.aspx");

The depth is not unlimited but I'm guessing there will be a limit to the number of levels you'll need to go.

</div><div>
</div>

This tutorial might help you....

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

Thanks.

this might help you  http://msdn.microsoft.com/en-us/magazine/dd347546.aspx#id0070003

thanks for your answers guys....these examples covers the basics...which is quite easy to implement. Im looking for something that can handle more complex structures and preferably can come up automatically as categories are added to the database without any manual tampering in global.asax

Basically I want to know if it is possible to dynamically generate the rounting table without registering them in Global.asax.

If not I will have to register 24 routes for the product catalogue (6 base routes with limit to 3 subcategories deep) itself and then a few for other kind of pages so a total of 26 routes...and it will have to be maintained everytime a new base category is registered then I have to register 4 new routes...it wont happend often but does anyone have any ideas...?

Basically I want URL like this

www.mywebsite.com/{category}/{category1}/{category2}/{category3}/{product}/

No fixed root pointer...any ideas?

I have temporarily fixed it with a route /catalog/ but it is not wanted  

www.mywebsite.com/catalog/{category}/{category1}/{category2}/{category3}/{product}/

IS this possible in ASP.NET or is the global.asax a necessary evil?

Hi,

manga75

I have temporarily fixed it with a route /catalog/ but it is not wanted  

www.mywebsite.com/catalog/{category}/{category1}/{category2}/{category3}/{product}/

IS this possible in ASP.NET or is the global.asax a necessary evil?

 

Please check the sample below,hope this helps.

http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

 

thanks but for if the application was running in MVC this would never have been a problem...it is webforms as posted in the question.

Hi,

manga75

...it is webforms as posted in the question.

 

Please try this:

Using Routing With WebForms

ASP.NET 4.0 WebForms Routing

How to: Use Routing with Web Forms

Hope this helps.

Thank you but I allready know the basics what Im looking for is how to generate the routes automatically from the database so I dont have to register them manually so it work truly like a datadriven site.

I have a database categories table that has a parent child relation so I can build and unlimited amount of subcategories

id (int)
categoryname (varchar)
active (bit)
rawurl (varchar) 
parent int (fk id)

id category active rawurl parent
1 sport TRUE /1/ null
2 winter TRUE /1/2/ 1
3 hockey TRUE /1/2/3/ 2
4 skates TRUE /1/2/3/4/ 3
5 Junior TRUE /1/2/3/4/5/ 4
6 Pro TRUE /1/2/3/4/6/ 4
7 Practise TRUE /1/2/3/4/6/7/ 6

I allready generate the treeview and store it in cache and thats basically what I want to be able to do with the routing aswell so the routing can reflect the database.

<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;" id="_mcePaste">
id category active rawurl parent
1 sport TRUE /1/ null
2 winter TRUE /1/2/ 1
3 hockey TRUE /1/2/3/ 2
4 skates TRUE /1/2/3/4/ 3
5 Junior TRUE /1/2/3/4/5/ 4
6 Pro TRUE /1/2/3/4/6/ 4
7 Practise TRUE /1/2/3/4/6/7/ 6
</div>

thoughts on "[RESOLVED] url routing with asp.net 3.5 or 4"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>