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. eclipse Dynamic web module相关问题

    大致因为java的web系统有多种类型,比如静态的和动态的,然后动态的java web project要设置dynamic web module,也就是动态网页模型,他必须要喝对应的服务器搭配好了才能 ...

  2. 11-22 JS中级复习

    1.this js的关键字, 用途:指向某一个对象. 如何判断this指向 函数(方法)内 一种以函数的方式调用(不带.) this指向winodw 一种以方法的形式调用(函数名前面带.)this指向 ...

  3. Linux命令第三篇

    作业三: 以操作文件的方式,新建一个用户alex echo "alex:x:1200:1200::/home/alex/:/bin/bash" >> /etc/pass ...

  4. javascript中的onmousewheel事件处理

    滚轮事件在不同浏览器会有一点点区别,一个像Firefox使用DOMMouseScroll ,FF也可以使用addEventListener方法绑定DomMouseScroll事件,其他的浏览器滚轮事件 ...

  5. arcgis 获得工具箱工具的个数

    import arcgisscripting import string; gp = arcgisscripting.create(9.3); ##多少个工具箱 toolboxes = gp.list ...

  6. 怎么让 Android 程序一直后台运行,像 QQ 一样不被杀死

    转自:https://blog.csdn.net/javazejian/article/details/52709857 作者:闭关写代码链接:https://www.zhihu.com/questi ...

  7. Java程序猿怎样高速理解Kubernetes

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/M2l0ZgSsVc7r69eFdTj/article/details/82892167 https: ...

  8. [Functional Programming] Functional JS - Pointfree Logic Functions

    Learning notes. Video. Less than: If you use 'ramda', you maybe know 'lt, gt'.. R.lt(2, 1); //=> ...

  9. 什么是 Spring Boot

    Spring Boot 介绍 Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...

  10. Hierarchical softmax(分层softmax)简单描述.

    最近在做分布式模型实现时,使用到了这个函数. 可以说非常体验非常的好. 速度非常快,效果和softmax差不多. 我们知道softmax在求解的时候,它的时间复杂度和我们的词表总量V一样O(V),是性 ...