2013-1126

IIS7移除响应头里边的服务器信息

作者: momy 分类: 编程开发 0 Comment »
摘要:IIS7移除响应头里边的Server, X-AspNet-Version, X-AspNetMvc-Version and X-Powered-By信息

1 X-AspNetMvc-Version
在Global.asax的Application_Start方法中加入

  MvcHandler.DisableMvcResponseHeader = true;

2 X-AspNet-Version

web.config中
<httpRuntime enableVersionHeader="false" />

3 X-Powered-By

web.config中
<httpProtocol>
       <customHeaders>
         <remove name="X-Powered-By" />
       </customHeaders>
</httpProtocol>


4 Server

using System;
using System.Web;
namespace Project.Infrastructure.Web.Modules.Http
{
    public class CustomHeaderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += OnPreSendRequestHeaders;
        }
        public void Dispose() { }
        void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
         //HttpContext.Current.Response.Headers.Remove("Server");
            // Or you can set something funny
        HttpContext.Current.Response.Headers.Set("Server", "CERN httpd");
        }
    }
}

在web.config添加以下配置

<system.webServer>
    <modules>
       <add name="CustomHeaderModule" type="StrongNamespace.HttpModules.CustomHeaderModule" />


标签: Server X-AspNet-Version X-AspNetMvc-Version X-Powered-By 阅读: 14343
上一篇: Android关于在TextView中设置DrawableLeft的问题 - 9856次
下一篇: FlowLayoutPanel Drag and Drop实现拖拽排序 - 19944次

向右滑动解锁留言