Everest Computers Blog About Computers and Web Design

Imagine the situation: you’re developing a website using classic ASP technology including “Include” directives. Obviously, all changes and amendments are done by you on your personal computer or a local server in your local computer network. After the changes, you upload the code to the web server, where the website is permanently hosted, and what do you find? The website is not working.

Amongst other reason it may also be because of the different root paths on your local computer and the remote web server. Different root directories don’t allow setting up the permanent path for Include if the website is to work on two different servers. I’ll show a trick to make it working.

Include directive can be of two variations: with “virtual” keyword and with direct “file” keyword. Usage of the virtual keyword indicates a path beginning with a virtual directory. Usage of the file keyword to indicate a relative path:

<!– #include virtual =”/html/header.inc” –>

<!– #include file =”headers\header.inc” –>

That’s ok if we know the directory and the asp file where Include is used is one of a kind. But what if they are scattered around the website, in different directories and it is necessary to point to a file in a specific location from all these different files around the website?

In this case we need to use “file” keyword because “virtual” simply doesn’t work. At leaset for me it definitely didn’t. So what I did is I specified the full path in the Include directive like

<!– #include file =”www.everestcomputers.co.uk\headerFiles\header.asp” –>

Did you know that you can use “.asp” instead of “.inc”? Me too, but it works and works fine - allows me to edit the incusion files and check the syntax in the same time.

But anyway, the above inclusion would work fine on the web server where the website is hosted. But what about the localhost or 127.0.0.1? There I’d need to add the following incusion:

<!– #include file =”localhost\headerFiles\header.asp” –>

That’s right. And here’s the trick. What we need to do is to create two files with different names of course - one for the web server and the other for localhost. Both will have the different paths like above. And we’re going to set up the default index files on the web server and the localhost differently - the name of the index file on the web server will be the name of the first file above, and the name of the index file on localhost will be the name of the second file above.

Here’s the example:

default path: root/directory1/directory2/

Index files setup: myFileWS.asp on the server; myFileLocal.asp on localhost, so www.everestcomputers.co.uk/directory1/directory2/ will bring up myFileWS.asp and localhost/directory1/directory2/ will bring up myFileLocal.asp.

Inside those two files we include the Incude directive with different paths that both point to the same file somewhere in the website structure, for example to \headerFiles\header.asp and the development is done!

It will be necessary to hardcode the server web address, but it can be changed if necessary. The small price to pay for the solution that works.

Comments are closed.

 
Powered by WordPress |  Admin
Copyright © 2007 - 2009 Everest Computers: Computer Support & Web Design. All rights reserved.