ASP.NET 2.0 ProfessionalIf you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I've successfully created a routing class which re-routes urls when someone types in: http://myurl/myfolder/{someletter}. This allows people to get some data from a database which starts with {someletter}, e.g. "a".
The folder called "myfolder" above contains a file in it's root called "default.aspx", e.g. http://myurl/myfolder/default.aspx which is just a signpost page and contains alphabet links to direct people to the url above. This all works fine.
However, I encounter a problem when I add another entry to the routing table which adds an extra level, e.g:
I've stepped over the code in my class which handles the RequestContext and implements IRouteHandler and I can see it trying to route when I just browse to "myfolder".
System.Web.Routing.Route r1 = new System.Web.Routing.Route("myfolder/{someletter}", new UrlRouting.MySimpleRouteHandler());
System.Web.Routing.Route r2 = new System.Web.Routing.Route("myfolder/{someletter}/{somearticle}", new UrlRouting.MySimpleRouteHandler());
I'm curious why you wouldn't have a listings page where instead of people actually typing a URL they could click on a link, directing them to the database where they could get a listing of the articles. Then they would be able to click on the link to the article and again not have to type URL's?
Sorry if I missed the whole point of your post.
You have no IF statement RegisterRoutes so how does it know whether you are feeding it a database or an article?
Hi,
thanks for your reply. Yes, I think you misunderstood my post, sorry. The process I'm trying to achieve is maintaining "friendly urls" for a legacy system.
As you mentioned, I do have a page where they can click on a letter and they will be able to see all articles begining with that letter. This works fine (see example 1 below).
I've got an encyclopaedia of health related articles (thousand's of them), so I have to maintain the following url structure, e.g:
which I thought would be handled by the following code:
System.Web.Routing.Route r2 = new System.Web.Routing.Route("myfolder/{someletter}/{somearticle}", new UrlRouting.MySimpleRouteHandler());
The code above however doesn't route correctly....any ideas why?
Quote:
Originally Posted by rstelma
Hi,
I'm curious why you wouldn't have a listings page where instead of people actually typing a URL they could click on a link, directing them to the database where they could get a listing of the articles. Then they would be able to click on the link to the article and again not have to type URL's?
Sorry if I missed the whole point of your post.
You have no IF statement RegisterRoutes so how does it know whether you are feeding it a database or an article?
Richard
Last edited by elwappo; May 26th, 2009 at 04:01 AM.
So, your code is not routing correctly but if you simply type the correct URL like http://mywebsite.com/encyclopaedia/a/acne/ you can get to the article just fine?
OK... I don't see what the problem is and I don't know enough either about the URL handlers and your particular implementation.
I did though find what looks like two fine articles on this subject with sample, example code which may give you a clue as to what is happening.
So, your code is not routing correctly but if you simply type the correct URL like http://mywebsite.com/encyclopaedia/a/acne/ you can get to the article just fine?
OK... I don't see what the problem is and I don't know enough either about the URL handlers and your particular implementation.
I did though find what looks like two fine articles on this subject with sample, example code which may give you a clue as to what is happening.
1. no, it doesn't handle the url if you just type in http://...../a/acne, because the routing class that I've written, handles this as the http request comes in. There's no physical file or folder that exists, the routing table deals with where to point the http request at runtime - this is what the {wildcardvalue} do in the system.web.routing.route() method.
It looks as if the routing class has a flaw in it's design, in that, you cannot add sub-wildcard routes:
System.Web.Routing.Route r1 = new System.Web.Routing.Route("myfolder/{someletter}")
and
System.Web.Routing.Route r2 = new System.Web.Routing.Route("myfolder/{someletter}/{somearticle}")
You have to add a some arbitary folder name in between for it to work, e.g. :
System.Web.Routing.Route r2 = new System.Web.Routing.Route("myfolder/{someletter}/article/{somearticle}").
Thanks for the links, nothing in there seems to cover my topic though. I've read many blogs on this and none of them seem to cover what I'm trying to achieve unfortunately. They all cover the basic urlrouting mechanism which I fully understand.