经典 asp 页面的 IIS 处理程序映射包含 (.inc) 文件

IIS Handler Mappings for classic asp page include(.inc) file

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

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

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

<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.

我想知道我需要什么才能让 include(.inc) 文件可以被 asp 页面recognized/read?

包括作品,但 Lankymart 的答案是正确的。

我创建了一个 helpers.inc 文件:

Sub MakeAMsg(MsgText)
    MsgBox MsgText
End Sub

我使用了 Include 并保留了 .inc 扩展名:

<script language=VBS>
<!--#include file=helpers.inc-->
makeamsg("This Used Include")
</script>

有效。我用 VBS 扩展重命名了 .inc:

<SCRIPT language=VBS src=helpers.vbs></SCRIPT>
<script language=VBS>
makeamsg("This Used Script tags with vbs extension")
</script>

这也行。

我检查了我的服务器,默认情况下 .vbs 被设置为 text/vbscript 的 mimetype。 (我正在设置另一个我没有更改任何东西的地方,它也有这个映射。)

所以使用#include 确实有效,但是将扩展名更改为 .vbs 或添加复制 .vbs mime 类型的 mime 类型会更好。

如果这一行是它在迁移后的代码中出现的样子(没有任何修改)

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

那么一件事就清楚了。

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

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

的文件类型

Note: Having client-side VBScript defined in the page will severely limited cross browser compatability because VBScript is only supported in older versions of Internet Explorer.


为什么 404.3

404.3 的原因是因为 IIS blocks unknown file types. To fix this you need to add a MIME type mapping in IIS which I wouldn't usually recommend as .inc is sometimes used as an extension for SSI files,但我们已经揭穿了映射 MIME 类型的理论。


为什么它不是 SSI

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

  1. 使用处理器标签

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

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

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

有用的链接