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

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

Response Header中不暴露Server(IIS)版本、ASP.NET及相关版本等信息_第1张图片

(以下转载自: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;
    }

    // 移除 Server
    app.Context.Response.Headers.Remove("Server");
}

三、移除 X-Powered-By

在Web.config文件中添加:


    
    
        
            
            
            
            
        
    

四、移除X-AspNet-Version

在Web.config文件中

你可能感兴趣的:(.Net,ASP.Net站点信息安全)