当前位置:首页 > 编程笔记 > 正文
已解决

Response Header中不暴露Server(IIS)版本、ASP.NET及相关版本等信息

来自网友在路上 165865提问 提问时间:2023-10-27 12:15:35阅读次数: 65

最佳答案 问答题库658位专家为你答疑解惑

ASP MVC开发的Web默认情况下会在请求的回应中暴露Server、X-AspNet-Version、X-AspNetMvc-Version、X-Powered-By等相关服务端信息,公开这些敏感信息会存在一定的安全风险。

X-SourceFiles标头用于被IIS / IIS Express中某些调试模块理解,它包含到磁盘上源文件的base64编码路径,并用于将页面生成的输出链接回该源文件,只在本机请求下生成,应用程序部署到实际服务器时,并不会出现,无需担心!

https://www.cnblogs.com/xixifusigao/p/3953279.html
https://www.orcode.com/question/1214535_kf9ca5.html

(以下转载自:https://www.cnblogs.com/namexiaoqi/p/10981224.html)


一、隐藏:X-AspNetMvc-Version

在Global.asax文件的Application_Start方法中添加:

MvcHandler.DisableMvcResponseHeader = true;

二、移除 Header 中的 Server

在Global.asax文件中添加: 

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{var app = sender as HttpApplication;if (app == null || app.Context == null){return;}// 移除 Serverapp.Context.Response.Headers.Remove("Server");
}

三、移除 X-Powered-By

在Web.config文件中添加:

<system.webServer><!-- 其它内容 --><httpProtocol><customHeaders><!-- 移除 X-Powered-By --><clear /><!-- 还可以添加自己的 X-Powered-By 做为标识 --><add name="X-Powered-By" value="bbb.com" /></customHeaders></httpProtocol>
</system.webServer>

四、移除X-AspNet-Version

在Web.config文件中<httpRuntime enableVersionHeader="false" />

<httpRuntime enableVersionHeader="false" />

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Response Header中不暴露Server(IIS)版本、ASP.NET及相关版本等信息":http://eshow365.cn/6-26020-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!