Skip to main content

removing unnecessary http headers in iis and asp.net

Server Headers:

To remove Server headers there are multiple solutions
Solution 1:
Add the below code snippet in global.asax file
protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("Server");
        }

Solution 2: (Preferred)
Download and install the latest version of urlscan tool (version 3.1) from the following link
32-Bit (x86):
64-Bit (x64):
After installing goto below location
C:\Windows\System32\inetsrv\urlscan
Open “UrlScan.ini” file in notepad as a Administrator

Update the value for RemoveServerHeader=1 from 0.

X-Powered-By Headers:

Solution 1:
Remove the X-Powered-By headers from IIS
Open IIS

Click on required website
Click on HTTP Response headers,
Right click on “X-Powered-By” and remove the header by clicking Yes
Solution 2:
Including the below lines to the <system.webServer> element of web.config
<httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
</httpProtocol>

 X-AspNet-Version:
Solution 1:
In web.config add this under System.Web
<httpRuntime enableVersionHeader="false"/>

Solution 2:
Add the below code snippet in global.asax file
protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("X-AspNet-Version ");
        }

Comments

Popular posts from this blog

Dependency Injection in MVC 5

Here I am going to explain how to implement dependency injection in MVC Project in detail including separate layers for getting data through Services and Repositories. Steps Step 1: open visual studio, goto File->New->Project Step 2: Select “Web” from left menu, “ASP.NET Web Application (.NET Framework)” from Project types list and give some name to application (I am giving it as DI). Step 3: Select “Empty” template, check MVC Checkbox below and click “OK” It will take little time to create the solution. Step 4: Open Solution Explorer, it will create the folder structure as shown below. Step 5: Now we are going to create DAL (Data Access Layer), where data is available, Right Click on Solution Explorer, Goto Add->New Project… Step 6: Select “Windows” from left menu, “Class Library” from Project list, give some name (DAL), click on OK. Step 7: “Class1.cs” will be opened . Right click on Class1.cs in solution explorer, click “Re...

implement hsts iis

We can implement HSTS using multiple approaches. Approach 1: PRE-REQUISITES: URL Rewrite module has to be installed from the below link https://www.microsoft.com/en-in/download/details.aspx?id=7435 Add the below code to web.config <?xml version= "1.0" encoding= "UTF-8" ?> <configuration>     <system.webServer>         <rewrite>             <rules>                 <rule name = "HTTP to HTTPS redirect" stopProcessing = "true" >                     <match url = "(.*)" />                     <conditions>       ...