【发布时间】:2021-03-27 08:51:14
【问题描述】:
我正在尝试从发布到 Azure 的“纯”Web api 应用程序(即无 MVC)返回的响应中添加/删除某些 http 标头。
我在VS2019的项目中添加了如下web.config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Content-Type-Options" value="nosniff"/>
<add name="X-Frame-Options" value="SAMEORIGIN"/>
<remove name="X-Powered-By"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
这在我使用 IISExpress 的开发环境中运行良好。当应用程序发布到 Azure 以用于未配置为多实例缩放的应用程序服务时,它也可以正常工作。但是,当应用服务配置为多实例扩展(在我的例子中是三个实例)时,来自应用的响应包含“X-Powered-By”并且没有“X-Content-Type-Options” ' 或 'X-Frame-Options'。
发布在我的开发机器上的 Out 文件夹中创建以下 web.config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="SAMEORIGIN" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\<apname>.exe" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>
我还验证了上面的 web.config 存在于 Azure 中应用服务的根目录中。
在 Azure 中的应用服务配置中是否还需要完成其他任何操作才能使用多实例扩展?
【问题讨论】:
-
你在 webapp 中使用哪个平台?
-
如果我的回复有帮助,请采纳为答案(点击回复旁边的标记选项将其从灰色切换为填写。),请参阅meta.stackexchange.com/questions/5234/…
-
我使用的是Windows平台
标签: azure-web-app-service asp.net-core-webapi asp.net-core-3.1