Forum Moderators: open

Message Too Old, No Replies

Coding a SSI

Can this be done in the ASP and not the HTML

         

chris_f

9:25 am on Jan 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi All,

When coding, if I want to put I file include in I have to leave the code. I was wondering there is a way of doing this in ASP. At the moment my code awalys looks like this.

<%
CODE
CODE
CODE
%>
<!--#include file="includedfile.asp"-->
<%
CODE
CODE
CODE
%>

Chris.

SuzyUK

10:03 am on Jan 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi chris_f

This is from "my bible" I understand it but haven't yet used it as I do not have IIS5 to test (well not on my server.)


SSI's are used to insert code from another page into the current one. All SSI are carried out before any ASP code is executed, this means that if you want to use your ASP code to determine what file to include, you CAN'T.

But You can (with correct version of IIS) use Server.Execute(path). this executes the ASP script specified by (path).

If (path) is an absolute path it should be for as ASP page within the same application space (i.e. same folder or one of its subfolders). (path may contain query string data)

I typed it out as written, because I can't take credit for this info ;)

I'll be experimenting later too ;)

Suzy

Dreamquick

10:29 am on Jan 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice answer Suzy! I wouldn't have thought of using server.execute quite like that but now you've mentioned it, it does seem embarassingly obvious...

The only incorrect point from your quote is that server.execute *doesn't* allow you to point it at a script name which includes query string information...

e.g. the following doesn't work under IIS 5.1 (if you remove the query string it works like a charm);

server.execute( "/page2.asp?bob=1" )

Another answer for the more traditional coder would be to encapsulate the code inside the include, including it at the start and then calling it later on.

This has the advantage of working under all IIS versions plus you ensure that the code inside the include doesn't expose unnecessary variables or constants, and you gain the advantage of having reasonably neat looking code (is it just me or do we all want the code to look nice?).


<!--#include file="includedfile.asp"-->
<%
CODE
CODE
CODE

'Trip the include code on demand
MyIncludeFunction()

CODE
CODE
CODE
%>

- Tony

chris_f

12:39 pm on Jan 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks All,

As I'm only calling includes and, am therefore, not using querystrings I'll try the following:

server.execute("/code/includefile.asp")

chris.