我有一个独立的Windows服务作为C#服务运行。我需要在所有响应中添加像"X-Xss-Protection“这样的自定义报头。我尝试在app.config文件中使用以下脚本,但这不会向响应中添加任何HTTP头。
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By"/>
<remove name="X-AspNet-Version"/>
<remove name="HTTPServer"/>
<remove name="Microsoft-IIS"/>
<add name="Strick-Transport-Security" value="max-age=31536000;includeSubDomains"/>
<add name="Content-Security-Policy" value="script-src 'unsafe-eval' https://www.google.com 'self' 'unsafe-inline'"/>
<add name="X-Xss-Protection" value="1; mode=block"/>
<add name="Feature-Policy" value="geolocation 'none'"/>
<add name="Cache-Control" value="no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0"/>
<add name="Pragma" value="no-cache"/>
<add name="Expires" value="0"/>
</customHeaders>
</httpProtocol>
</system.webServer>发布于 2021-05-17 14:16:42
无法通过IDispatchMessageInspector.BeforeSendReply方法成功插入标头的原因可能是因为您没有在接口上添加[CustomBehavior]标记。
如下所示添加标签:
[CustomBehavior]
Public interface IServicehttps://stackoverflow.com/questions/67515925
复制相似问题