ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> The base href tag --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
144 active users
3104 visitors today
4667 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

The sURLTest array

I then loop through an array (defined in include/config.asp as we'll see below), searching for strings that will define which server I am running on. When we find a match we add a sub-folder to the path.

Here are the arrays in include/config.asp:

// ============================================
// base href - the URL of your pages
// ============================================
// if a string in sURLTest is found, then the offset is applied from
// sURLOffset. As an example, I want my base hrefs to be
// http://CoverYourASP.com/ on production server and
// http://localhost/cya/ on development server.
var sURLTest = new Array (
   '.com',      // if this found in server name..
   'localhost'
   );

var sURLOffset = new Array (
   '',         // ..apply this offset
   'cya'
   );

As shipped in the download I first look for ".com" in the server name (obviously you should change both of these arrays to fit your circumstances). If a ".com" is found, then I don't need any sub-folder, so I leave the sURLOffset empty. The final base href is therefore "http://CoverYourASP.com/".

If "localhost" is found, then "cya" is added to the server name, and I end up with "http://localhost/cya/". Bingo!

Featured sponsor
My favorite resources

Selling products online - read how James does it now



New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!