Asp.Net Remove Unwanted Headers
原文: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,添加如下的重写规则:

<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的更多相关文章
- vim - Simple commands to remove unwanted whitespace
http://vim.wikia.com/wiki/Remove_unwanted_spaces 1. manual commandremove trailing whitespace::%s/\s\ ...
- IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称
微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1 ; 若为1,则使用 ...
- 手写一个简版 asp.net core
手写一个简版 asp.net core Intro 之前看到过蒋金楠老师的一篇 200 行代码带你了解 asp.net core 框架,最近参考蒋老师和 Edison 的文章和代码,结合自己对 asp ...
- 移除IIS默认的响应头(转载)
转载地址:http://www.cnblogs.com/dudu/p/iis-remove-response-readers.html 在IIS+ASP.NET的运行环境,默认情况下会输出以下的响应头 ...
- 移除IIS默认的响应头
在IIS+ASP.NET的运行环境,默认情况下会输出以下的响应头(Response Headers): 那如何移除这些响应头呢?下面我们来一个一个移除. 1. 移除Server 借助IIS URL R ...
- Spring boot中使用springfox来生成Swagger Specification小结
Rest接口对应Swagger Specification路径获取办法: 根据location的值获取api json描述文件 也许有同学会问,为什么搞的这么麻烦,api json描述文件不就是h ...
- astyle代码格式化
Artistic Style 1.24 A Free, Fast and Small Automatic Formatterfor C, C++, C#, and Java Source Code 项 ...
- 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 ...
- Linux Kdump 机制详解
文章目录 1. 简介 1.1 安装 1.2 触发 kdump 1.3 调试 kdump 1.3.1 安装 debuginfo vmlinux 1.3.2 编译 kernel 1.4 kdump-too ...
随机推荐
- 【HDOJ】1059 Dividing
多重背包. #include <stdio.h> #include <string.h> #define mymax(a, b) (a>b) ? a:b ]; ]; vo ...
- ☀【CSS3】形状
CSS3shapeshttp://www.css3shapes.com/ <!DOCTYPE html> <html lang="zh-CN"> <h ...
- Ehcache Java开源缓存框架
一.ehcache.xml 配置详解 单机配置: <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
- ArcServer,ArcSDE,ArcIMS,ArcEngine
ArcServer,ArcSDE,ArcIMS,ArcEngine是ESRI的四种产品ArcGIS Server 与 ArcIMS功能相似,是将地图发布成服务供调用的ArcSDE 是空间数据引擎,是将 ...
- 深入学习JS: __doPostBack函数
在.NET中,所有的服务器控件提交到服务器的时候,都会调用__doPostBack这个函数,所以灵活运用这个函数对于我们的帮助还是很大的. 比如,在我们写程序的时候经常会需要动态的生成一些控件,最简单 ...
- windows下面配置jdk环境变量
在环境变量中添加如下: Path D:\Program Files\Java\jdk1.6.0_26\binJAVA_HOME D:\Program Files\Java\jdk1.6.0_26CLA ...
- Qualcomm Android display架构分析
Android display架构分析(一) http://blog.csdn.net/BonderWu/archive/2010/08/12/5805961.aspx http://hi.baidu ...
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Spring学习总结
spring是当前流行的一个框架.在学习spring之前当然的先准备一些jar包.可以在官网找找,(也可以留言,网盘分享): 基于IDEA环境学习. 第一天完成的任务: 1.使用spring框架输出一 ...
- Windows下安装Eric5时出现的“Sorry, please install QtHelp.”问题解决办法
解决Windows下安装Eric5时出现的“Sorry, please install QtHelp.”问题 PyQt4在Windows中使用了DirectX作为加速,不过,PyQt4没有使用最新 ...