Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 25th, 2009, 04:27 PM
Authorized User
Points: 192, Level: 3
Points: 192, Level: 3 Points: 192, Level: 3 Points: 192, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2006
Location: God's country , United Kingdom.
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default URL Routing

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:

http://myurl/myfolder/{someletter}/{somearticle} (So people can get a specifIc article under that letter).

For some reason whenever i browse to http://myurl/myfolder/ it tries to route to: http://myurl/myfolder/{someletter}/{somearticle} for some bizarre reason? Does anybody know why this is?

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".

Here's my code:

privatevoid RegisterRoutes(RouteCollection Routes)
{

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());

Routes.Add(r1);
Routes.Add(r2);

}

protectedvoid Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}

I cannot work out why this is occurring. Any help would be much appreciated....
Regards
Reply With Quote
  #2 (permalink)  
Old May 25th, 2009, 04:42 PM
Friend of Wrox
Points: 2,077, Level: 18
Points: 2,077, Level: 18 Points: 2,077, Level: 18 Points: 2,077, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 594
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old May 26th, 2009, 03:48 AM
Authorized User
Points: 192, Level: 3
Points: 192, Level: 3 Points: 192, Level: 3 Points: 192, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2006
Location: God's country , United Kingdom.
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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:

http://mywebsite.com/encyclopaedia/a (shows all articles beginning with "a")
http://mywebsite.com/encyclopaedia/a/abscess (shows the details of a particular article, e.g. "abscess")

So what I've got is (example 1):

a url routed page which shows all articles that begin with a particular letter - the following code works perfectly fine:

System.Web.Routing.Route r1 = new System.Web.Routing.Route("myfolder/{someletter}", new UrlRouting.MySimpleRouteHandler());
(which handles http://mywebsite.com/encyclopaedia/a, http://mywebsite.com/encyclopaedia/b, http://mywebsite.com/encyclopaedia/c, etc)

and what also I want is another url routing entry to handle things like:

http://mywebsite.com/encyclopaedia/a/acne/ (which would show the details of the article)

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 View Post
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.
Reply With Quote
  #4 (permalink)  
Old May 26th, 2009, 12:06 PM
Friend of Wrox
Points: 2,077, Level: 18
Points: 2,077, Level: 18 Points: 2,077, Level: 18 Points: 2,077, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 594
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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.

http://chriscavanagh.wordpress.com/2...bforms-sample/

http://haacked.com/archive/2008/03/1...-webforms.aspx

Please post back when you get it solved.

Thanks,
Richard
Reply With Quote
  #5 (permalink)  
Old May 26th, 2009, 04:27 PM
Authorized User
Points: 192, Level: 3
Points: 192, Level: 3 Points: 192, Level: 3 Points: 192, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2006
Location: God's country , United Kingdom.
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by rstelma View Post
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.

http://chriscavanagh.wordpress.com/2...bforms-sample/

http://haacked.com/archive/2008/03/1...-webforms.aspx

Please post back when you get it solved.

Thanks,
Richard
Hi Richard,
in answer to your question:

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}").

This works fine, but doesn't achieve exactly what I want, e.g :
http://mywebsite.com/encyclopaedia/a/article/acne/



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.

Regards
Kevin
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically Routing - Chapter 9 dpleal BOOK: Professional K2 blackpearl ISBN: 9780470293058 1 July 30th, 2010 08:57 PM
URL Routing elwappo ASP.NET 3.5 Professionals 2 June 11th, 2009 01:20 AM
Routing Error - Ruby on Rails dodgevipe1 Intro Programming 1 May 5th, 2007 06:03 PM
Excel eMail Routing Slip Kenny Alligood Excel VBA 0 June 28th, 2003 07:51 AM



All times are GMT -4. The time now is 10:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.