Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The following changes allow you to remove these HTTP response headers in Azure <em>without</em> writing a custom HttpModule.</p> <p>Most of the information on the net is out of date, and involves UrlScan (which has since been integrated into IIS7, but with the <code>RemoveServerHeader=1</code> option removed). Below is the neatest solution I've found (thanks to <a href="http://www.davidaiken.com/2011/10/04/hiding-response-headers/" rel="noreferrer">this blog</a>, <a href="https://stackoverflow.com/a/7338448/590558">this answer</a>, and <a href="http://www.bugwriter.me/2010/01/removing-unnecessary-http-header-server.html" rel="noreferrer">this blog</a> combined).</p> <p><s>To remove <strong>Server</strong>, go to Global.asax, find/create the <code>Application_PreSendRequestHeaders</code> event and add the following (thanks to <a href="https://stackoverflow.com/a/7338448/590558">BK</a> and <a href="http://www.bugwriter.me/2010/01/removing-unnecessary-http-header-server.html" rel="noreferrer">this blog</a> this will also not fail on Cassini / local dev):</s></p> <p>Edited April 2014: You can use the PreSendRequestHeaders and PreSendRequestContext events with native IIS modules, but do not use them with managed modules that implement IHttpModule. Setting these properties can cause issues with <a href="http://www.asp.net/aspnet/overview/web-development-best-practices/what-not-to-do-in-aspnet,-and-what-to-do-instead#presend" rel="noreferrer">asynchronous requests</a>. The correct version is to use BeginRequest event.</p> <pre><code> protected void Application_BeginRequest(object sender, EventArgs e) { var application = sender as HttpApplication; if (application != null &amp;&amp; application.Context != null) { application.Context.Response.Headers.Remove("Server"); } } </code></pre> <p>To remove <strong>X-AspNet-Version</strong>, in the web.config find/create <code>&lt;system.web&gt;</code> and add:</p> <pre><code> &lt;system.web&gt; &lt;httpRuntime enableVersionHeader="false" /&gt; ... </code></pre> <p>To remove <strong>X-AspNetMvc-Version</strong>, go to Global.asax, find/create the <code>Application_Start</code> event and add a line as follows:</p> <pre><code> protected void Application_Start() { MvcHandler.DisableMvcResponseHeader = true; } </code></pre> <p>To remove <strong>X-Powered-By</strong>, in the web.config find/create <code>&lt;system.webServer&gt;</code> and add:</p> <pre><code> &lt;system.webServer&gt; &lt;httpProtocol&gt; &lt;customHeaders&gt; &lt;remove name="X-Powered-By" /&gt; &lt;/customHeaders&gt; &lt;/httpProtocol&gt; ... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload