Question

The main domain includes a virtual file like this:

<!--#include virtual="/includes/functions/index.asp"-->

That in turn includes a whole bunch of function files, something like this:

<!--#include virtual="/includes/function/includedfunctionone.asp"-->
<!--#include virtual="/includes/function/includedfunctiontwo.asp"-->
<!--#include virtual="/includes/function/includedfunctionthree.asp"-->

But when I try to include these from a subdomain, they can't be found. I presume because the server is searching for the /includes/functions/index.asp within the subdomain itself.

I can access the main include from the subdomain changing it to a relative path:

<!--#include file="../includes/functions/index.asp"-->

However, that breaks when the main file calls the list of nested virtual includes. And I don't want to change all of those to #include file, because they need to be absolute paths.

What I've Tried 1

I have tried using a full server path like this:

D:\domains\website.com\wwwroot\includes\functions\index.asp

... but that gives me 'ASP 0126' Include file not found

What I've Tried 2

I've also tried including a full url, like this:

http://website.com/includes/functions/index.asp

... but that gives me a fat bold 500 error with no indication of the specific error.

Was it helpful?

Solution

Here's my comment as an answer.

In IIS manager, setup the folder containing your includes as a virtual directory of each website where you need to use it - then you can use

<!--#include virtual="/YourVirtualDirectory/YourInclude.asp"-->

More details here - Scroll down to "The Virtual Keyword"

OTHER TIPS

I hope that will help you... This works for me with the subdomain folder in the main folder of the website.

Step 0 : Make sure that you can access the relative parent folder path using your scripts (IIS > Website Properties > Base folder > Configuration Button > Options tab > Check if not checked)

On your subdomain you can try this script :

Step 1 : Get the content of your asp functions file

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim File : Set File = Fso.OpenTextFile(Server.MapPath("../PathOfYourFuncFile.asp"), 1)
Dim FileContent : FileContent = File.ReadAll
File.Close
Set File = Nothing

Step 2 : Clear <% and %> in FileContent variable

FileContent = Replace(FileContent, "<", "")
FileContent = Replace(FileContent, ">", "")
FileContent = Replace(FileContent, "%", "")

Step 3 : Use the script in your current page

Execute FileContent

Step 4 : Try to call your functions and subs

If that works you can easily optimise the script to get a clear code. (Sorry for my bad english)

Edit :

this will not corrupt html content returned by functions or subs. Files loaded have to be only asp not html content with asp scripts inside.

Function StreamReader(vFic, vCharset)

    Dim oContent
    Dim oStreamReader : Set oStreamReader = CreateObject("ADODB.Stream")
    With oStreamReader
        .Open
        .Charset = vCharset
        .LoadFromFile vFic
        oContent = .ReadText
        .Close
    End With
    Set oStreamReader = Nothing

    StreamReader = oContent
End Function

FileContent = StreamReader(Server.MapPath("File2.asp"), "utf-8")
FileContent = Replace(FileContent, Chr(Asc("<")) & Chr(Asc("%")), "")
FileContent = Replace(FileContent, Chr(Asc("%")) & Chr(Asc(">")), "")

Execute FileContent
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top