asp.net mvc移除X-AspNet-Version、X-AspNetMvc-Version、Server 2019-12-06 09:29

asp.net mvc程序部署到IIS,,返回的HTTP头中包含Server, X-Powered-By, 和 X-AspNet-Version、X-AspNet-Version信息. 这些信息有时给攻击者找寻你的站点漏洞提供的依据.

如下图所示:

 

 

 

1.移除X-AspNet-Version

在webconfig中做如下配置:

 

 

2.移除X-AspNetMvc-Version

在Global.asax中做如下配置

 

 3.移除Server

3.1自定义server处理模型:

复制代码
//移除http相应中的server Server: Microsoft-IIS/10.
    public class CustomHeaderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += OnPreSendRequestHeaders;
        }
        public void Dispose()
        {
            throw new NotImplementedException();
        }
        void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            //HttpContext.Current.Response.Headers.Remove("Server");
            // 你可以在此设置
            HttpContext.Current.Response.Headers.Remove("Server");
        }

    }
复制代码

3.2在webconfig中做如下配置:

<add name="CustomHeaderModule" type="EUQ.Boss.App_Start.CustomHeaderModule" />

 

 

4.移除X-Powered-By: ASP.NET

 打开IIS管理器,定位到当前站点,找到HTTP响应标头

删除节点:

 

 

 

如上操作相当于在webconfig中做如下配置:

 <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By" />
            </customHeaders>
        </httpProtocol>

 

posted @   梦亦晓  阅读(1920)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示