asp-classic - 经典 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页面识别/读取?
解决方案
如果这一行是它在迁移代码中的显示方式(没有任何修改)
<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 页面中运行服务器端脚本只有三种方法;
使用处理器标签
<% ... %>
使用带有
runat="server"
属性的脚本标签。<script language="VBScript" runat="server"> ... </script>
#include
使用指令添加 SSI 。<!-- #include virtual = "somefile.asp" -->
有用的链接
对 IIS 7.5 的回答不会将 *.inc 作为 ASP Classic 运行 (不使用
.inc
客户端脚本扩展的参数)。
推荐阅读
- spring-boot - 处理异常时返回错误的错误响应
- reporting-services - SSRS 报告卡住加载状态,甚至 executionlog3 说已完成
- android - 将 ViewModel 用于 ListView 和
在列表视图中? - python - 在 plotly 折线图上隐藏一条线
- java - 为什么要在 Java 的接口 X 中声明 X 类型的变量?
- sql - Microsoft 在查询中使用 ORDER BY 中的 switch 语句时访问更改数据类型
- python - 如何使用 user_passes_test 查看特定页面?
- dafny - 验证 dafny 中的谓词是否适用于所有整数
- python - 计算 pyspark 数据框中的出现次数
- javascript - 随机图像和配对文本选择 javascript