【问题标题】:Is it possible to include virtual files from the main domain in a subdomain in asp?是否可以在 asp 的子域中包含来自主域的虚拟文件?
【发布时间】:2014-03-17 18:41:54
【问题描述】:

主域包含一个像这样的虚拟文件:

<!--#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

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

&lt;!--#include file="../includes/functions/index.asp"--&gt;

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

我的尝试 1

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

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

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

我的尝试 2

我也尝试过包含完整的网址,如下所示:

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

... 但这给了我一个粗体 500 错误,没有指明具体错误。

【问题讨论】:

  • 您是否尝试过虚拟目录(即有一个文件夹作为多个站点的虚拟目录)?
  • 不,我没有,我会调查一下并试一试,谢谢 :)
  • 查看此页面 - 向下滚动到“虚拟关键字”w3schools.com/asp/asp_incfiles.asp
  • @MartinHansenLennox 您使用的是什么版本的OS / IIS
  • 对于所有帮助过的人,我很抱歉没有早点回来,有紧急事情发生了,我忘记了这一切。 @John - 虚拟目录很有效,感谢您的链接。如果您可以将其放入答案中,我会将其标记为答案。作为记录,我们使用的是 Win Server 2008 和 IIS 7。

标签: asp-classic include subdomain


【解决方案1】:

这是我的评论作为答案。

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

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

More details here - 向下滚动到“虚拟关键字”

【讨论】:

    【解决方案2】:

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

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

    在您的子域上,您可以试试这个脚本:

    第 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 步:清除 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
    

    【讨论】:

    • 所有这些只是为了使用一个可以通过Virtual Directory 映射到子域站点轻松访问的包含?
    • 您也确实意识到response.write 或字符串变量中的任何 HTML 都会被这些语句破坏(至少前两个语句)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 2013-06-08
    • 2013-09-03
    • 2012-10-03
    • 1970-01-01
    相关资源
    最近更新 更多