原文:http://blogs.msdn.com/b/varunm/archive/2013/04/23/remove-unwanted-http-response-headers.aspx

原文:http://blog.paulbouwer.com/2013/01/09/asafaweb-excessive-headers-and-windows-azure/

Server

在Global.asax.cs中添加红色部分代码

        protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("Server");
}

如果使用的是Web Api 2.0的话,以上方法不支持,需要修改注册表

@echo off
setlocal
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters
reg add %regpath% /v DisableServerHeader /t REG_DWORD /d

复制上方代码,保存为批处理文件,然后运行

另外种方法借助IIS URL Rewrite Module,添加如下的重写规则:

 
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="REMOTE_ADDR" />
</allowedServerVariables>
<outboundRules>
<rule name="REMOVE_RESPONSE_SERVER">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>

重写规则存放在C:\Windows\System32\inetsrv\config\applicationHost.config中。

X-Powered-By

在web.config中添加以下代码

<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>

X-AspNet-Version

在web.config中添加以下代码

<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>

X-AspNetMvc-Version

在Global.asax.cs中添加红色部分代码

        protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MvcHandler.DisableMvcResponseHeader = true;
}

或者在nuget下添加NWebsec包,移除以上Headers,未测试

Asp.Net Remove Unwanted Headers的更多相关文章

  1. vim - Simple commands to remove unwanted whitespace

    http://vim.wikia.com/wiki/Remove_unwanted_spaces 1. manual commandremove trailing whitespace::%s/\s\ ...

  2. IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称

    微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1                ; 若为1,则使用 ...

  3. 手写一个简版 asp.net core

    手写一个简版 asp.net core Intro 之前看到过蒋金楠老师的一篇 200 行代码带你了解 asp.net core 框架,最近参考蒋老师和 Edison 的文章和代码,结合自己对 asp ...

  4. 移除IIS默认的响应头(转载)

    转载地址:http://www.cnblogs.com/dudu/p/iis-remove-response-readers.html 在IIS+ASP.NET的运行环境,默认情况下会输出以下的响应头 ...

  5. 移除IIS默认的响应头

    在IIS+ASP.NET的运行环境,默认情况下会输出以下的响应头(Response Headers): 那如何移除这些响应头呢?下面我们来一个一个移除. 1. 移除Server 借助IIS URL R ...

  6. Spring boot中使用springfox来生成Swagger Specification小结

    Rest接口对应Swagger Specification路径获取办法: 根据location的值获取api   json描述文件 也许有同学会问,为什么搞的这么麻烦,api json描述文件不就是h ...

  7. astyle代码格式化

    Artistic Style 1.24 A Free, Fast and Small Automatic Formatterfor C, C++, C#, and Java Source Code 项 ...

  8. Installing IIS 8.5 on Windows Server 2012 R2

    原文 Installing IIS 8.5 on Windows Server 2012 R2 Introduction This document describes how to install ...

  9. Linux Kdump 机制详解

    文章目录 1. 简介 1.1 安装 1.2 触发 kdump 1.3 调试 kdump 1.3.1 安装 debuginfo vmlinux 1.3.2 编译 kernel 1.4 kdump-too ...

随机推荐

  1. 在linux系统下怎么安装两个nginx

    在linux下安装nginx的时候,一般在./configure的阶段会要求通过prefix设置安装路径.因此,在./configure的时候指定不同的prefix就可以安装多个nginx啦. 值得注 ...

  2. oracle时间模型

    Oracle在9i或者早期的版本,对于性能优化方面,主要采用命中率模型,后面的版本,也保留着命中率模型,比如在awr报告中,Instance Efficiency Percentages (Targe ...

  3. 实验记录贴 —— 账号同步实验 RTX 和 LDAP(AD域)

    目前,公司有多个系统,RTX,邮箱(MD),OA,NC. 这些系统之间,如果要实现单点登录的话,账户肯定需要同步,或者某一种映射机制. 如果所有数据都和中央账号数据库(LDAP,这里是AD域)看齐,那 ...

  4. (转载)AS3中的mouseEnabled与mouseChildren

    (转载)http://www.cnblogs.com/gongchen/archive/2013/05/09/3069055.html mouseEnabled与mouseChildren都是用来确定 ...

  5. CMake 入门实战 | HaHack

    CMake 入门实战 | HaHack undefined

  6. 搜索(DFS)

    不知道为什么~除了我室友其他的同学都觉得DFS很简单~且比BFS容易得多........我真心不觉得啊T T~我真心觉得BFS比DFS简单得多................= = 为了把DFS完全搞 ...

  7. jQuery 的属性操作方法

    jQuery 属性操作方法 下面列出的这些方法获得或设置元素的 DOM 属性. 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的 ...

  8. Java开发常用代码

    1. 字符串有整型的相互转换 String a = String.valueOf(2); //integer to numeric string int i = Integer.parseInt(a) ...

  9. JavaScript实现遮罩层

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. lcx源代码以及免杀的研究

    之前和Random大神讨论了一下免杀的问题,他给出了一个比较不错的想法,使用debug版本发布可以过很多杀软.顺便看了下lcx的源码,发现其代码不算特别复杂,于是乎就在这分析一下. 报毒情况 因为使用 ...