如何在不触及源代码文件 (Global.asax.cs) 的情况下从标头响应中删除 X-AspNetMvc-Version?

Chi*_*wal 4 c# asp.net-mvc-4

我需要X-AspNetMvc-Version从大量应用程序的响应头中禁用。托管应用程序的服务器只有应用程序的内容和配置文件Global.asax, web.config, app.config,源代码文件 (*.cs) 驻留在其他团队中。

我只能找到解决方案作为添加 MvcHandler.DisableMvcResponseHeader = true;Global.asax.cs. 任何涉及使用任何配置文件的替代解决方案?

小智 6

不幸的是,唯一的方法是在 Global.asax 中使用以下代码: MvcHandler.DisableMvcResponseHeader = true;


Bri*_*den 5

在您的 web.config 中将 enableVersionHeader 设置为 false 是一种替代方法,我更喜欢将 web.config 更改为像您一样的处理程序解决方案,显然,因为您不需要访问 global.asax.cs 来进行更改:

只需将此行复制到 web.config 的<system.web>部分:

<httpRuntime enableVersionHeader="false" />
Run Code Online (Sandbox Code Playgroud)

http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.enableversionheader(v=vs.110).aspx

http://madskristensen.net/post/Remove-the-X-AspNet-Version-header

  • 谢谢布莱恩,但是你谈到的解决方案可以处理 X-AspNet-Version,而我需要 X-AspNetMvc-Version。 (4认同)