IIS:尝试在计算机上配置 IIS 以使用包含文件时出现 500 服务器错误

IIS: Getting a 500 Server Error when trying to configure IIS on machine to work with include files

在我的 wwwroot 主文件夹中,我有一个 index.html 文件。在其中我引用了包含文件,例如:

<!--#include file="include/globalSearch_index.inc"-->
<!--#include file="include/footer_index.inc"-->

在同一文件夹中,我还有一个名为 "include" 的文件夹,其中包含这些文件。 *.inc 文件仅包含可重复使用的片段 html

默认情况下,如果我尝试使用 localhost/index.html 查看此内容,这些说明将被忽略,并且仅呈现 index.html 页面上的内容。我按照此 page 中的说明在 IIS 中设置了适当的处理程序映射。

但是现在,我收到以下错误页面。 我已经重置了 IIS 并重新启动了计算机(顺便说一句,我试图在我的本地计算机上执行此操作,而不是单独的服务器)。根据该错误页面上的说明,我检查了我是否安装了 .Net Extensibility Feature(我有)。但是,我的 wwwroot 文件夹中没有 web.config 文件。如果我确实需要其中之一,那么其中需要包含什么?

还有什么我需要尝试的吗?

又折腾了半天终于搞定了运行。对于在遇到类似问题后应该碰巧导航到这里的任何人:因此,在 IIS 中创建该模块映射时,似乎缺少最后一步。在单击 "OK" 之前在弹出窗口中填写必填字段后,单击 "Request Restrictions" 按钮。在第二个弹出窗口中选中 "Invoke handler only if request is mapped to" 复选框,然后在两个弹出窗口中点击确定,这应该可以解决问题。

这会在您创建映射的文件夹中创建一个 web.config,如下所示:

   <?xml version="1.0" encoding="UTF-8"?>
       <configuration>
        <system.webServer>
            <handlers>
                <add name="SSI-html" path="*.html" verb="*" modules="ServerSideIncludeModule" resourceType="File" />
            </handlers>
        </system.webServer>
    </configuration>