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


免責聲明!

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



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