Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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
 
Old June 11th, 2009, 01:20 AM
Corin Louis
Guest
 
Posts: n/a
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.




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 04:35 AM
Excel eMail Routing Slip Kenny Alligood Excel VBA 0 June 28th, 2003 07:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.