【问题标题】:Adding x-frame-Options in web.config return error 500在 web.config 中添加 x-frame-Options 返回错误 500
【发布时间】:2018-06-27 11:45:22
【问题描述】:
我在 web.config 中添加了 X-frame-Options。
这是我的 web.config
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
重启 IIS 后出现 500 错误!!!
谁能帮我找出问题所在?
【问题讨论】:
标签:
iis
asp.net-web-api
x-frame-options
【解决方案1】:
修改你的customHeaders如下:
<customHeaders>
<clear />
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
我怀疑您的应用程序位于虚拟文件夹中,如果是这种情况,则处理两个 web.config 文件。第一次是全球性的,第二次是你的。所以你最终有两个customHeaders 集合。
博文IIS 7: But why do I get a 500.19 更详细地解释了它发生的原因以及如何解决它。
【解决方案2】:
您添加 CustomHeaders 的位置错误。正确的位置是:
....
</system.web>
<system.webServer>
<security>
<requestFiltering>
<verbs allowUnlisted="true">
<add verb="OPTIONS" allowed="false" />
</verbs>
</requestFiltering>
</security>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="ALLOW" />
<remove name="X-Powered-By" />
<add name="X-XSS-Protection" value="1; mode=block" />
<add name="X-Content-Type-Options" value="nosniff" />
</customHeaders>
</httpProtocol>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
....
其他选项对您的应用程序安全很有用。