Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server Side Includes (w/ IIS5)

Status
Not open for further replies.

flanakin

Programmer
Mar 21, 2000
158
US
I know how to do an include...

<!--#include file=&quot;whatever.asp&quot;-->

I want to know how to base the file off of a variable...

<%
If x=1 Then
strFilePath = &quot;whatever.asp&quot;
Else
strFilePath = &quot;nothing.asp&quot;
End If
%>
<!--#include file=&quot;<%= strFilePath %>&quot;-->

Ok, NO, this does not work, but I want something that will work like it. I just want to know if there is ANY way to send the SSI a variable for the file. All it is is a string, so it HAS to be possible. Let me know!!! Thanks! ~[ cid ]~
cid@cjd-web.com
 
Three possible ways to do this, depending on your situation.

First:
You can just read the file in using FSO. This is a good option if the file you are including has no ASP code to be executed.
see faq333-504 for more details on reading/writing files with FSO.

Second:
If you have ASP code that needs to be executed, then you can use Server.Execute (ASP 3.0). The problem with server.execute is that the calling page does not get any access to the variables or functions from the page it is calling.

Ex: (in abc.asp)
dim someVar
someVar = &quot;def.asp&quot;
Server.Execute someVar

'in this scenario, abc.asp does not get any access to
'the variables or functions in def.asp. I'm not sure if
'def.asp gets access to abc.asp.

This would be useful for scripts that are totally self contained.

Third:
Utilize context switching.

<%if someVar then%>
<!--#include file=&quot;a.asp&quot;-->
<%else%>
<!--#include file=&quot;b.asp&quot;-->
.
.
.
<%end if%>

'notice how the delimiters are needed in order
'for it to run.


hope this helps you out
leo
 
I knew about the first and third. The second is what I was looking for! That is great! Thanks a bunch!!! I'll try that! ~[ cid ]~
cid@cjd-web.com
 
When I attempt to run Server.Execute, the page gives me this error:

The RPC server is unavailable.

What does this mean? ~[ cid ]~
cid@cjd-web.com
 
I do have IIS5. As far as I could tell, that was the only stipulation, and it is being met. Is there a registry key that needs to be set or something? I know you have to have one to use the #exec command. But, that's for executables, not ASP. ~[ cid ]~
cid@cjd-web.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top