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



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

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

helpers.inc 文件在默认.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.

我想知道我需要什么才能让 asp 页面识别/读取 include(.inc) 文件?

如果此行是它在迁移代码中的显示方式(无需任何修改)

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

有用的链接

  • IIS 7.5 的答案不会将 *.inc 作为 ASP Classic 运行(不使用.inc客户端脚本扩展的参数)。

  • 关于 IIS 上的 MIME 类型和扩展筛选之间的区别的答案?.

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

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

Sub MakeAMsg(MsgText)
MsgBox MsgText
End Sub

我使用了包含并保留了.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设置为文本/vbscript的模仿类型。(我正在设置另一个我没有更改任何内容的地方,它也有这个映射。

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

最新更新