首页 > 解决方案 > 经典 asp 页面包含 (.inc) 文件的 IIS 处理程序映射

问题描述

我正在将一个经典的 ASP 站点迁移到 IIS 10 中托管的较新版本的 Windows 服务器。

加载 default.asp 页面时,我在浏览器的开发者工具中发现,网络选项卡显示找不到 helpers.inc 文件。但它与默认页面位于同一文件夹中。

通过以下代码在 default.asp 页面中调用 helpers.inc 文件:

<script src="helpers.inc" language="VBScript" defer="true"></script>

如果我尝试从浏览器访问 helpers.inc 文件,我将收到此错误:

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Most likely causes:
•It is possible that a handler mapping is missing. By default, the static file handler processes all content.
•The feature you are trying to use may not be installed.
•The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
•If ASP.NET is not installed.

我尝试使用 %windir%\system32\inetsrv\asp.dll 可执行文件为 *.inc 文件添加处理程序映射,但它似乎不起作用。给我一个新的错误:

HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.

Most likely causes:
•The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.

我想知道我需要什么让包含(.inc)文件可以被asp页面识别/读取?

标签: asp-classicinclude

解决方案


如果这一行是它在迁移代码中的显示方式(没有任何修改)

<script src="helpers.inc" language="VBScript" defer="true"></script>

然后一件事很清楚。

这不是 SSI (服务器端包含)

该标记将具有.inc扩展名的文件定义为客户端VBScript。但目前,您还没有告诉 IIS.inc是允许用作text/vbscript.

注意:在页面中定义客户端 VBScript 将严重限制跨浏览器的兼容性,因为 VBScript 仅在旧版本的 Internet Explorer中受支持。


为什么404.3

原因404.3是因为IIS 阻止了未知文件类型。要解决此问题,您需要在 IIS 中添加一个 MIME 类型映射,我通常不建议这样做,因为.inc它有时用作 SSI 文件的扩展名,但正如我们已经揭穿的那样,映射 MIME 类型的理论是可行的方法。


为什么它不是 SSI

在经典 ASP 页面中运行服务器端脚本只有三种方法;

  1. 使用处理器标签

    <%
        ...
    %>
    
  2. 使用带有runat="server"属性的脚本标签。

    <script language="VBScript" runat="server">
        ...
    </script>
    
  3. #include使用指令添加 SSI 。

    <!-- #include virtual = "somefile.asp" -->
    

有用的链接


推荐阅读