我们在开发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头的更多相关文章

  1. 【转】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 ...

  2. ASP.NET 连接 SQL Server 和 Oracle 教程

    临近期末,有很多同学都问我怎么关于ASP.NET 连接 SQL Server 和 Oracle 的问题.由于人太多了,我也不能一一去帮忙,就写了这篇博客.希望对大家有用处. 首先,前期准备是要安装数据 ...

  3. 无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试。

    无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试. a>.DCOM配置里的属性灰色不可用的解决方法,   1>.管理工具->组件服务 ...

  4. [Asp.Net Core] Blazor Server Side 扩展用途 - 配合CEF来制作带浏览器核心的客户端软件 (二) 可运行版本

    前言 大概3个星期之前立项, 要做一个 CEF+Blazor+WinForms 三合一到同一个进程的客户端模板. 这个东西在五一的时候做出了原型, 然后慢慢修正, 在5天之前就上传到github了. ...

  5. 奇葩问题: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 ...

  6. jexus asp.net Linux Web Server

    Jexus简介 Jexus web server for linux 是运行在Linux上的Web服务器.其安装和部署及其简单,直接支持Asp.net . 下载Jexus wget http://li ...

  7. 关于ASP.NET Session State Server

    最近公司开发的一个网站因为访问量增大,需要添加多台Web Server来进行负载均衡. 但是在做负载均衡前需要将一些原来固定存储在单台机器上的东西分离出来,使之能单独存在在一个独立的机器上,其中就有S ...

  8. ASP.NET用SQL Server中的数据来生成JSON字符串

    原文引自:  作者: 缺水的海豚  来源: 博客园  发布时间: 2010-09-21 21:47  阅读: 6136 次  推荐: 0   原文链接   [收藏] 摘要:ExtJs用到的数据内容基本 ...

  9. ASP.NET中使用Server.Transfer()方法在页间传值 实例

    以下代码在VS2008中测试通过 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...

随机推荐

  1. Android Studio 使用笔记:快捷键

    开发工具中的快捷键是必不可少了,AS中在Help菜单中单击 Default Keymap Reference 浏览器会连接到官网,打开对应你操作系统的快捷键页面,这是一个pdf文件.Mac系统独立一份 ...

  2. 【转】如何彻底删除SVN中的文件和文件夹(附恢复方法)

    这里假设SVN项目的目录为 /data/svn/project,我们想排除trunk/test.exe文件和trunk/notallowed/目录,操作步骤如下及执行的svn命令(在svn安装目录的b ...

  3. jQuery CSS 操作函数

    CSS 属性 描述 css() 设置或返回匹配元素的样式属性. height() 设置或返回匹配元素的高度. offset() 返回第一个匹配元素相对于文档的位置. offsetParent() 返回 ...

  4. android 细节之 AndroidRuntimeException:This message is already in use

    今天在做项目处理消息队列的时候.遇到了这样一个问题.一个异常.AndroidRuntimeException:This message is already in use. 我当时的详细业务需求情境为 ...

  5. Linux虚拟机安装完centos后环境配置

    linux下面安装软件 yum install rpm -ivh 编译安装 三部曲:./configure make make install 卸载 rpm -e 安装方法 1)通过yum安装软件 需 ...

  6. 如何在xampp中运行php文件 (WINDOWS)

    from:http://blog.sina.com.cn/s/blog_5e87822501011os2.html 入门: 如何在xampp中运行php文件 (WINDOWS) 安装XAMPP启动ap ...

  7. Android 自定义权限 (<permission> <uses-permission>)

    在android系统的安全模型中,应用程序在默认的情况下不可以执行任何对其他应用程序,系统或者用户带来负面影响的操作.如果应用需要执行某些操作,就需要声明使用这个操作对应的权限. (在manifest ...

  8. POJ3487[稳定婚姻]

    The Stable Marriage Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2974 Accepted ...

  9. 《从零开始学Swift》学习笔记(Day 19)——函数参数传递

    原创文章,欢迎转载.转载请注明:关东升的博客   函数的语法格式如下: func 函数名(参数列表) -> 返回值类型 { 语句组 return 返回值 } 关键字是func. 多个参数列表之间 ...

  10. EasyPlayer-RTSP-Android安卓播放器播放RTSP延迟优化策略,极低延时!

    EasyPlayer-RTSP-Android安卓RTSP播放器低延迟播放延时优化策略 EasyPlayer-RTSP-Android播放器是一款专门针对RTSP协议进行过优化的流媒体播放器,其中我们 ...