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 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 12th, 2009, 11:23 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 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 15th, 2009, 06:15 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

After doing some additional reseearch, I've noticed if I add a folder reference betwen {someletter} and {somearticle}, the routing works fine, e.g.

System.Web.Routing.Route r2 = new System.Web.Routing.Route("myfolder/{someletter}/anotherfolder/{somearticle}", new UrlRouting.MySimpleRouteHandler());


Is it the case that you can't route to same folder with multiple {parameters}? Hope somebody can help me with clearing this up.
Regards
Reply With Quote
  #3 (permalink)  
Old June 11th, 2009, 01:20 AM
Banned
 
Join Date: Apr 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is a global variable in PHP that holds the current domain name.

$_SERVER[ 'HTTP_HOST' ];

Here's an example using strpos that prints a different h1 tag depending on which domain is typed in the browser.

if( strpos( $_SERVER[ 'HTTP_HOST' ], "xxxx.com" ) !== false )
echo "<h1>xxxx.com</h1>";
elseif( strpos( $_SERVER[ 'HTTP_HOST' ], "yyyy.com" ) !== false )
echo "<h1>yyyy.com</h1>";

You could also embed this in a function to make the code cleaner.

function fromDomain( $domain ) {
if( strpos( $_SERVER[ 'HTTP_HOST' ], $domain ) !== false )
return true;
else
return false;
}

if( fromDomain( "xxxx.com" ) )
...


Hope this helps.
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
Routing Error - Ruby on Rails dodgevipe1 Intro Programming 1 May 5th, 2007 06:03 PM
extract URL from Favorites (.URL Files) PhilHawks VB.NET 2002/2003 Basics 2 November 2nd, 2004 03:35 AM
Excel eMail Routing Slip Kenny Alligood Excel VBA 0 June 28th, 2003 07:51 AM



All times are GMT -4. The time now is 05:49 AM.


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