我有 2 个 Web 应用程序:MVC 和 Blazor webassembly。
在 MVC 项目中,我能够按照 Microsoft documentation 中的说明,通过在启动类中添加 HSTS 中间件来设置应用程序以强制执行 strict-transport-security
。
问题是:如何配置 Blazor 网络程序集以在其响应标头中强制实施严格传输安全性?
我尝试将以下 web.config
文件添加到项目中:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<security xdt:Transform="Insert">
<requestFiltering removeServerHeader="true" />
</security>
<httpProtocol xdt:Transform="Insert">
<customHeaders>
<remove name="X-Powered-By" />
<add name="strict-transport-security" value="max-age=31536000" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
但添加此配置文件后,我无法部署应用程序。