Click here to Skip to main content
15,902,893 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I want to avoid IIS and asp.net version disclosure during HTTP 404 not found error response in c#.

What I have tried:

I have set enableversionheader as false in the config file. Added URL Rewrite
<rewrite>
        <outboundRules>
            <rule name="ChangeServerHeader">
                <match serverVariable="RESPONSE_SERVER" pattern=".*" />
                <action type="Rewrite" value="Private Server" />
            </rule>
        </outboundRules>
    </rewrite>

Also in the global.asax file have set code to remove the server header
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
     var app = sender as HttpApplication;
     if (app != null && app.Context != null)
     {
          app.Context.Response.Headers.Remove("Server");
      }
}
Posted
Updated 6-Feb-23 3:17am
v3
Comments
Andre Oosthuizen 6-Feb-23 9:46am    
Some solutions found at -
https://www.codeproject.com/Questions/5293226/Asp-net-core-website-getting-404-error-in-producti
OR
https://techcommunity.microsoft.com/t5/iis-support-blog/remove-unwanted-http-response-headers/ba-p/369710
OR
https://stackoverflow.com/questions/38529123/asp-net-core-404-error-on-iis-10

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