asp.net 移除Server, X-Powered-By, 和X-AspNet-Version头
我们在开发Asp.net中,最后部署在IIS上. 然后发送HTTP请求,返回的HTTP头中包含Server, X-Powered-By, 和 X-AspNet-Version信息. 这些信息有时给攻击者找寻你的站点漏洞提供的依据. 如下图我们通过FireBug查看到:
移除X-AspNet-Version很简单,只需要在Web.config中增加这个配置节:
<httpRuntime enableVersionHeader="false" />
public class RemoveServerInfoModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
//no code nescessary
} public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);
} void context_PreSendRequestHeaders(object sender, EventArgs e)
{
// strip the "Server" header from the current Response
HttpContext.Current.Response.Headers.Remove("Server");
}
#endregion
}
上面这段代码会arise exceptioin,我们最好这样实现PreSendRequestHeaders方法:
void context_PreSendRequestHeaders(object sender, EventArgs e)
{
try
{
HttpApplication app = sender as HttpApplication;
if (null != app && null != app.Request && !app.Request.IsLocal && null != app.Context && null != app.Context.Response)
{
var headers = app.Context.Response.Headers;
if (null != headers)
{
headers.Remove("Server");
}
}
}
catch (Exception)
{
throw;
}
}
最后在Web.config中配置这个HttpModule:
<httpModules>
<add name="RemoveServerInfoModule" type="MyWeb.RemoveServerInfoModule"/>
</httpModules>
For IIS 7:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<add name="RemoveServerInfoModule" type="MyWeb.RemoveServerInfoModule"/>
</modules>
</system.webServer>
这样就OK了, 你再运行Asp.net web application时, Server,X-AspNet-Version等信息已经不显示了.
希望对您开发,有帮助.
asp.net 移除Server, X-Powered-By, 和X-AspNet-Version头的更多相关文章
- 【转】Asp.NetMve移除HTTP Header中服務器信息Server、X-AspNet-Version、X-AspNetMvc-Version、X-Powered-By:ASP.NET
默認情況下Chrome中截獲的HTTP Header信息: Cache-Control: Content-Encoding:gzip Content-Length: Content-Type:text ...
- ASP.NET 连接 SQL Server 和 Oracle 教程
临近期末,有很多同学都问我怎么关于ASP.NET 连接 SQL Server 和 Oracle 的问题.由于人太多了,我也不能一一去帮忙,就写了这篇博客.希望对大家有用处. 首先,前期准备是要安装数据 ...
- 无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试。
无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试. a>.DCOM配置里的属性灰色不可用的解决方法, 1>.管理工具->组件服务 ...
- [Asp.Net Core] Blazor Server Side 扩展用途 - 配合CEF来制作带浏览器核心的客户端软件 (二) 可运行版本
前言 大概3个星期之前立项, 要做一个 CEF+Blazor+WinForms 三合一到同一个进程的客户端模板. 这个东西在五一的时候做出了原型, 然后慢慢修正, 在5天之前就上传到github了. ...
- 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved
"This file could not be checked in because the original version of the file on the server was m ...
- jexus asp.net Linux Web Server
Jexus简介 Jexus web server for linux 是运行在Linux上的Web服务器.其安装和部署及其简单,直接支持Asp.net . 下载Jexus wget http://li ...
- 关于ASP.NET Session State Server
最近公司开发的一个网站因为访问量增大,需要添加多台Web Server来进行负载均衡. 但是在做负载均衡前需要将一些原来固定存储在单台机器上的东西分离出来,使之能单独存在在一个独立的机器上,其中就有S ...
- ASP.NET用SQL Server中的数据来生成JSON字符串
原文引自: 作者: 缺水的海豚 来源: 博客园 发布时间: 2010-09-21 21:47 阅读: 6136 次 推荐: 0 原文链接 [收藏] 摘要:ExtJs用到的数据内容基本 ...
- ASP.NET中使用Server.Transfer()方法在页间传值 实例
以下代码在VS2008中测试通过 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...
随机推荐
- Yarn源码分析之MRAppMaster上MapReduce作业处理总流程(一)
我们知道,如果想要在Yarn上运行MapReduce作业,仅需实现一个ApplicationMaster组件即可,而MRAppMaster正是MapReduce在Yarn上ApplicationMas ...
- gen_server边缘
我们以Module代表gen_server的callback模块 1, 实现gen_server behaviour的模块会产生一个新的process么? 毫无疑问,太会了!通过调用proc_lib: ...
- [Tomcat]无法使用tomcat6.exe启动服务解决办法, The system cannot find the Registry key for service 'tomcat7'
重新配置环境变量后,可以使用startup.bat启动服务, 但是无法使用tomcat6.exe启动服务, 错误信息: [2011-03-10 18:51:49] [warn] The system ...
- eclipse 遇关键字enum编译问题解决
今天公司系统升级 JDK1.4 到 JDK1.5, 结果工程在eclipse中编译不能通过: Enumeration enum = ………… 但是eclipse报错: Multiple markers ...
- Problem 500!!! (Project Euler 500)
题目大意:求出最小的正整数,它的约数有$2^{500500}$个. 思路:考虑将一个数质因数分解,如果它的约数有$2^{500500}$个, 那么每个质因子的指数一定是$2^k-1$这样的形式. 如果 ...
- 转载:tar 解压缩命令~
转载自:http://blog.csdn.net/dunyanan1/article/details/38869059tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文 ...
- 去OpenCVManager,大部分为转载,仅当自己学习使用
去OpenCVManager方法,可以参考这篇博客http://blog.csdn.net/yanzi1225627/article/details/27863615,可以用,挺好的.我这里只是做个总 ...
- svn 更新文件冲突,提示中文乱码解决
问题描述: update 操作提示错误信息,中文乱码 和 “Please execute the 'Cleanup' command.” Cleanup 操作报错: 解决办法: 1. 工具下载(sql ...
- Carries
Carries frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise. Unfortunately ...
- delphi小知识 点(if条件符,to_date)
1.if条件 与:and 或:or 不等于:<> 等于:= 例子: if(j=1)and(nFH<>0) then begin tLCH:=Trim(copy(tSAMPLEI ...