asp.net mvc移除X-AspNet-Version、X-AspNetMvc-Version、Server


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM