Click here to Skip to main content
14,692,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In the network in chrome browser i have checked server vession in the response headers for some requests.

I have added below code in the global.asax file but it's not working for some requests.

I want to hide server property from response headers in all requests.

If you could help me in this, It would be appreciated.

What I have tried:

I have added below code in global.asax file in some events.

public void Init(HttpApplication app)
        {
            app.PreRequestHandlerExecute += app_PreRequestHandlerExecute;
        }
        protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("Server");
            Response.Headers.Remove("X-AspNet-Version");


            Response.Headers.Remove("X-Powered-By");
            //HttpContext.Current.Response.Headers.Remove("Server");
            //Response.Headers.Set("Server", "N/A");

        }
        private void app_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            try
            {
                HttpContext.Current.Response.Headers.Remove("X-Powered-By");
                HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
                HttpContext.Current.Response.Headers.Remove("Server");
                HttpContext.Current.Response.Headers.Remove("MicrosoftSharePointTeamServices");
                //Response.Headers.Set("Server", "N/A");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }


Suppose in Get response it is not showing server header but in options response it is showing. Please suggest me the solution.
Posted
Updated 4-Jun-18 1:41am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900