是否可以在asp的子域中包含主域的虚拟文件?

时间:2014-03-17 18:41:55

标签: asp-classic include subdomain

主域包含如下虚拟文件:

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

反过来又包含了一大堆函数文件,如下所示:

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

但是当我尝试从子域中包含这些内容时,它们无法找到。我认为是因为服务器正在子域内搜索/includes/functions/index.asp

我可以从子域访问 main 包含,将其更改为相对路径:

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

但是,当主文件调用嵌套虚拟包含列表时会中断。而且我不想将所有这些更改为#include file,因为它们必须是绝对路径。

我尝试过1

我尝试使用像这样的完整服务器路径:

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

...但是这给了我'ASP 0126' Include file not found

我尝试过的事情

我还尝试了一个完整的网址,如下所示:

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

...但是这给了我一个胖的粗体500错误,没有任何特定错误的迹象。

2 个答案:

答案 0 :(得分:2)

这是我的评论作为答案。

在IIS管理器中,将包含您的包含的文件夹设置为您需要使用它的每个网站的虚拟目录 - 然后您可以使用

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

More details here - 向下滚动到&#34;虚拟关键字&#34;

答案 1 :(得分:0)

我希望这会对你有所帮助...... 这适用于网站主文件夹中的子域文件夹。

步骤0:确保您可以使用脚本访问相对父文件夹路径 (IIS&gt;网站属性&gt;基本文件夹&gt;配置按钮&gt;选项标签&gt;检查是否未选中)

在您的子域名中,您可以尝试以下脚本:

第1步:获取asp函数文件的内容

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

步骤2:清除&lt;%和%&gt;在FileContent变量

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

第3步:使用当前页面中的脚本

Execute FileContent

第4步:尝试调用你的函数和子函数

如果可行,您可以轻松优化脚本以获得清晰的代码。 (抱歉我的英语不好)

修改:

这不会破坏函数或子函数返回的html内容。加载的文件必须只是asp而不是内部使用asp脚本的html内容。

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
相关问题