Server Information Revealed

For the benefit of those who land here through a google/bing search:: Here's the summary of steps:

Step 1: Create a class that derives from IHttpModule (and IDisposable to clean up when we're done):

public class MyCustomModule : IHttpModule, IDisposable
{
private HttpApplication _httpApplication;
private static readonly List<string> HeadersToCloak = new List<string>
{
"Server",
"X-AspNet-Version",
"X-AspNetMvc-Version",
"X-Powered-By"
};
}

Step 2: Get a reference to the intrinsic context in the IHttpModule.Init method, and assign an event handler to the PreSendRequestHeaders event:

public void Init(HttpApplication context)
{
_httpApplication = context; context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}

Step 3: Now the headers can be removed like so:

private void OnPreSendRequestHeaders(object sender, EventArgs e)
{
if (null == _httpApplication)
{
return;
} if (_httpApplication.Context != null)
{
var response = _httpApplication.Response;
HeadersToCloak.ForEach(header => response.Headers.Remove(header));
}
}

Step 4: Now register this module in your root web.config under the system.webserver (if running IIS 7.0 integrated mode more details here):

<configuration>
<system.webServer>
<modules>
<add name="MyCustomModule" type="<namespace>.MyCustomModule "/>
</modules>
</system.webServer>
</configuration>

Hidden Directories Detected On Server

Another way is to create a handler in your web.config file that will return the 404 status code.

namespace MyNameSpace
{
public class NoAccessHandler: IHttpHandler
{ #region IHttpHandler Members public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
context.Response.StatusCode = 404;
} #endregion
}
}

in your web.config:

<httpHandlers>
<add verb="*" path="docs/*" validate="false" type="MyNameSpace.NoAccessHandler"/>
</httpHandlers> <system.webServer>
<handlers>
<add name="NoAccess" verb="*" path="docs/*" preCondition="integratedMode" type="MyNameSpace.NoAccessHandler"/>
</handlers>
</system.webServer>

C# 移除Response Header,403调整返回为404Make IIS return a 404 status code instead of 403的更多相关文章

  1. RobotFramework下的http接口自动化Get Response header 关键字的使用

    Get Response header 关键字用来获取http请求返回的http响应头部数据. 常见的Response Header: Header 解释 示例 Accept-Ranges 表明服务器 ...

  2. ASP.NET MVC中移除冗余Response Header

    本文主要介绍如何优化ASP.NET MVC使用IIS时Response Header中的不必要的信息 默认的,创建一个ASP.NET MVC项目,会在Response Header中包含一些敏感的信息 ...

  3. 【应用服务 App Service】如何移除App Service Response Header中包含的服务器敏感信息

    问题描述 有些情况下,当应用部署到App Service上后,在有些Response Header中,可以看见关于服务器的一些信息,这样会导致隐藏的安全问题,所以可以在web.config中移除某些关 ...

  4. 【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)

    问题描述 在Azure App Service上部署了站点,想要在网站的响应头中加一个字段(Cache-Control),并设置为固定值(Cache-Control:no-store) 效果类似于本地 ...

  5. Tomcat 中响应头信息(Http Response Header) Content-Length 和 Transfer-Encoding

    户端(PC浏览器或者手机浏览器)在接受到Tomcat的响应的时候,头信息通常都会带上Content-Length ,一般情况下客户端会在接受完Content-Length长度的数据之后才会开始解析.而 ...

  6. 转:PHP--获取响应头(Response Header)方法

    转:http://blog.sina.com.cn/s/blog_5f54f0be0102uvxu.html PHP--获取响应头(Response Header)方法 方法一: ========== ...

  7. upstream timed out (110: Connection timed out) while reading response header from upstream, client:

    遇到的问题 之前没配置下面这段,访问时候偶尔会出现 504 gateway timeout,由于偶尔出现,所以不太好排查 proxy_connect_timeout 300s;proxy_read_t ...

  8. recv() failed (104: Connection reset by peer) while reading response header from upstream

    2017年12月1日10:18:34 情景描述: 浏览器执行了一会儿, 报500错误 运行环境:  nginx + php-fpm nginx日志:  recv() failed (104: Conn ...

  9. HTTP 响应头信息(Http Response Header) Content-Length 和 Transfer-Encoding

    Tomcat 中响应头信息(Http Response Header) Content-Length 和 Transfer-Encoding 客户端(PC浏览器或者手机浏览器)在接受到Tomcat的响 ...

随机推荐

  1. WebStorm中使用npm包管理器

    1.首先安装Node.js,安装之后添加NodeJs的安装路径到系统Path环境变量,在控制台之中测试node,与npm命令是否工作正常. 2.配置npm的源为国内的淘宝镜像,这里不推荐使用cnpm ...

  2. NodeJS 连接接MySQL

    NodeJS 连接接MySQL MySQL是常用数据库,作为后端模块,nodejs可以提供了mysql接口 安装 $ npm install mysql 测试代码 var mysql = requir ...

  3. Schaepher 博客目录

    update: 2017-03-16 福州大学2015年秋软件工程实践课 软工课程作业目录 软工实践课程总结 团队博客 软件案例分析优秀链接汇总 Android Android学习笔记: (一):th ...

  4. ReactNative如何在JS中引用原生自定义控件(rn变化太快,网上很多教程有坑,这个我研究后可用,特意分享)

    直接写一个Demo例子,有相关功底的肯定明白,会对特别的地方进行提醒,本文基于https://blog.csdn.net/lintcgirl/article/details/53489490,但是按此 ...

  5. 开发入门,学Java还是学大数据?

    经常有人问,我想学习开发,到底是学Java好还是学大数据好?或者是,学习大数据还有必要学Java吗?      依我说,这个提问的标准答案是:两者都学.      先来甩两张图.      一张是腾讯 ...

  6. Creating an LMDB database in Python

    LMDB is the database of choice when using Caffe with large datasets. This is a tutorial of how to cr ...

  7. node-cache

    From: https://www.npmjs.com/package/node-cache Simple and fast NodeJS internal caching. A simple cac ...

  8. 大疆无人机M100相关问题解决过程

    1.遥控器升级问题 iOS端使用app升级,重复尝试了5次+,还是无法升级.卸载app重新安装,依旧是无法升级.使用Android app升级,一次搞定. 2.飞行器固件升级(云台别选错了) http ...

  9. ORA-12514 TNS:LISTENER DOES NOT CURRENTLY KNOW OF SERVICE REQUESTED IN CONNE

    对比Oracle服务器地址,端口号,还有实例名(也就是服务名).修改tnsnames.ora  在Oracle客户端的安装目录底下. 然后用sqlplus [用户名]/[密码]@[服务命名] 服务命名 ...

  10. Docker入门 - 003 Docker 实例

    Docker Hello World Docker 允许你在容器内运行应用程序, 使用 docker run 命令来在容器内运行一个应用程序. 输出Hello world runoob@runoob: ...