隐藏ASP.NET MVC的版本信息,使其不在HTTP Header中显示

隐藏ASP.NET MVC的版本信息,使其不在HTTP Header中显示。

一、隐藏: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文件中添加:

<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" />

猜你喜欢

转载自www.cnblogs.com/namexiaoqi/p/10981224.html
今日推荐