【发布时间】:2019-03-08 18:46:08
【问题描述】:
我正在将经典 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.
我想知道我需要什么才能让 asp 页面识别/读取 include(.inc) 文件?
【问题讨论】:
-
我的理解(我可能错了)是 .inc 文件被视为只是常规文本文件,并且更多地用于模板集成而不是包含 asp 代码的页面,尽管 VBscript 包含在如果包含在 asp 页面中,.inc 文件仍将执行。默认情况下,它们当然不会被 IIS 视为与 .asp 文件相同的文件。我一直避免使用它们,因为我从来没有真正看到过这一点(事实上,它们看起来很危险)。首先检查 .inc 文件中包含的内容,但您可能只需要添加 MIME 类型即可。
-
@Adam,它只是 VBScript 函数。我试过如果我将 helpers.inc 中的代码复制到脚本标签中,页面就会正确加载。抱歉不熟悉处理程序映射,您提到添加 MIME 类型,是在 IIS 中,单击网站/应用程序->MIME 类型->在那里添加新的 MIME 类型?如果是,我应该在这里使用什么 MIME 类型?文本/纯文本?非常感谢。
-
我可能会等待其他人发表评论,因为我不能 100% 确定 inc 文件。但是是的 text/plain 将是我使用的 MIME 类型。但是,只是重申一下;如果您的 inc 文件位于公共目录中,则它们的源代码将被公开。
-
如果只是VB函数,为什么不使用?我管理一个古老的经典 ASP 应用程序,这就是为此加载 VB 函数的方式。
-
阅读@Lankymart 发布的重复问题似乎设置mime 映射对于inc 文件来说是个坏主意,因为它们显然不打算由IIS 直接提供服务。这很有意义。您收到的错误消息是正确的,IIS 应该阻止您通过 HTTP 加载 inc 文件。问题是你没有正确地包括它们(正如已经回答的那样)。使用 inc 文件作为 SSI 不需要 mime 映射。
标签: asp-classic include