Click to See Complete Forum and Search --> : make site thru asp


djeet
06-16-2006, 06:59 AM
Hi,
I have been creating websites with plain HTML with a dash of Javascript. Never used asp in my life :) But a few days back I visited a site which I unfortunately am forgetting at this moment had something like this in the source code:
<!--#include file (asp) starts here-->
But couldn't figure out what it is. Now, one of my friends says that the header, footer and such common things are created once and named suppose: header.asp, footer.asp and then are 'included'. Is that it?
if yes, then pls I would like to learn this technique. Pls help.

Terrorke
06-16-2006, 07:31 AM
Yep totally correct.

You can put things you will use on serveral pages in one asp file and just include it in all your pages.

The advantage of this is when you have to update, you will only have to do this in the included page.

Here's a quick example :

Your basic page

<html>
<head>
Head content goes here
</head>
<Body>
<!-- #include file="Header.asp" -->
...
Your page content
...
</body>
</html>


Lets say your header pages includes some navigation links.


<%
response.Write("<a href=home.asp>Home</a> <a href=contact.asp>Contact</a>")
...
%>


So every page you want your link displayed in, you can use an include of the header page.

This shoul give you an idea of working with include files.

Grtz

djeet
06-17-2006, 12:41 AM
First of all thanks a lot! the code worked , I just copy-pasted what U gave and it is working will try to learn it from today.
but one more question: my friend just a few mins back gave me this code:
<!--#include virtual="/includes/inc_header.asp"-->
and U wrote 'file' instead of 'virtual' what is difference?
Which to use?
Once again, thanks a lot.

russell
06-17-2006, 01:34 AM
rule of thumb -- always use include virtual, instead of include file.

the difference is that include virtual means the path of the include file is relative to the root. include file means the path is relative to the file. poor practice to do anything relative to the file. main reason is maintainability/extensibility.

both work fine, but if you are slash-dotting paths (include file, or even links like href="../" ) then maintenance becomes a nightmare on a large site. also a very minor security issue, which i wont get into now but if you're curious i'll expand.

long and short is use include virtual, not inclue file.

cheers :)

djeet
06-17-2006, 01:47 AM
Hi,
I replaced file and wrote virtual. It worked then refreshed the page thru F5, I got this error msg:
There is a problem with the page you are trying to reach and it cannot be displayed. bla bla
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Error Type:
Active Server Pages, ASP 0126 (0x80004005)
The include file 'header.asp' was not found.
/inc/17june/index.asp, line 12

so I replaced virtual to file and it started working fine. I didn't even touch header.asp in this whole process. index.asp and header.asp are in the same folder.

djeet
06-17-2006, 02:05 AM
And I have just discovered that when I refresh the page thru F5 the error appears. But if I close IE then open it thru: http://localhost/inc/17june/index.asp
then the page opens correctly even if virtual is written.
Why is that so?

russell
06-17-2006, 03:43 AM
the path is relative to the root in virtual, to the file with file.

suppose your directory looks like this

c:\mySite\includes\include.asp
c:\mySite\default.asp

then "mySite" is the root.

from default.asp the "virtual" path to the include file is /includes/include.asp
the "file" path is ../includes/include.asp

now if they are in the same directory then the path is just include.asp

the problem is that you don't have i pathed correctly.

a leading slash as in /includes/file.asp, means -- start navigating the file system from the root. Without a leading slash, you are telling the OS to navigate from the current directory

russell
06-17-2006, 03:44 AM
one of the nice features of doing it this way is that you can put all of your include files in one directory and the path to them is the same from anywhere in your site

djeet
06-17-2006, 04:42 AM
Hi,
I hope U will do answer even though I am stuck at simple things. But, U C I am new 2 this concept. So pls help me.
This is where I am keeping the pages (index.asp, header.asp and footer.asp):
C:\Inetpub\wwwroot\17June
do U mean 2 say I make another folder named 'include' and put my header, footer pages in it. :confused: And if U don't mean that, then, in index.asp I will be writing :
<!-- #include file="header.asp" --> OR
<!-- #include virtual="header.asp" -->
Isn't it?
The page displays when 'file' is written ( which I think means that the path is correct, isn't it? ) then why not when it is 'virtual'. Pls elaborate. I won't mind if U expand and write everything U want to. Because it will help me a lot.

russell
06-17-2006, 12:46 PM
It is ok to use "include file." I'm just saying that for a large site u should use "virtual"

let me try to demonstrate:

C:\Inetpub\wwwroot\17June\
-- index.asp
-- header.asp
-- footer.asp

The "include file" path is relative to the file that does the including. So for index.asp you would just say <!--#include file="header.asp"--> becuase C:\Inetpub\wwwroot\17June\ is implied. This is exactly the same way that links work. As I'm sure you know, if you had another page in the same directory, you'd link to it like this href="page2.asp" -- no need to say http://www.mysite.com/17June/page2.asp -- the path is relative to the current file.

Now back to the include files. With the same directory structure, to use include virtual, the path is relative to the root of the web site which in your site is C:\Inetpub\wwwroot\ so the include virtual looks like this
<!--#include virtual="/17June/header.asp"-->

The advantage of doing this is that you can put all of your includes in one directory, and the include directive is the same for every page in your site.

Let's add a couple of directories to your site:

C:\Inetpub\wwwroot\
-- 17June\
-- index.asp
-- page2.asp
-- 17December\
-- index.asp
-- page2.asp
-- admin\
-- index.asp
-- signup.asp
-- login.asp
-- newsletters\
-- 2005\
-- january.asp
-- february.asp
-- 2006\
-- january.asp
-- february.asp
-- march.asp
-- includes\
-- header.asp
-- footer.asp

now the "include virtual" path to header.asp is the same from any display page. it is always "/includes/header.asp" but the "include file" path is different depending on which display page. From C:\Inetpub\wwwroot\17june\index.asp the "file" path is "../includes/header.asp" and from C:\Inetpub\wwwroot\admin\newsletters\2006\january.asp it is "../../../includes/header.asp.

make sense?

djeet
06-20-2006, 12:29 AM
Dear Russel,
I am in debt for what u have done. :) u have provided me and i hope a lot of other people such a nice answer. It will definitely help. Once again, thanks a lot!
PS: I will implement the 'include' thing just as u told to; right now I'm busy with another task. And I don't think I won't understand what u have written.
Bye.

Divyakedia
06-26-2006, 05:45 AM
Hi,
I read this post and it has helped me a lot. I had started working on a site and now I am doing it the 'include' way. Now, what I want to ask is that: I have made header , footer in 2 different asp pages since they will be same throughout the site. Now, I have a link to my products page, is it possible that the header& footer remain as they are and the content of the index page gets replaced by the products page's content. Or do I make a page called 'products.asp' and there write in " include virtual=...". Is there some way as V used to do via frames.
I hope I have made my question clear.