当前位置:编程学习 > asp >>

ASP.Net自定义重写Http Server标头

Net中我们为了安全或其他原因起见 可能需要修改我们的标头报文等

以下方法我们通过使用HTTP Module来使用编程的方式来去除或修改它

首先我们自定义一个类CustomServerHeaderModule继承自IHttpModule 并为PreSendRequestHeaders事件创建事件处理程序

代码如下:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Cloud.ApiWeb.Models
{
    public class CustomServerHeaderModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += OnPreSendRequestHeaders;
        }
        public void Dispose()
        {
        }
        void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            //移除Server标头
            //HttpContext.Current.Response.Headers.Remove("Server");
            //重新设置Server标头
            HttpContext.Current.Response.Headers.Set("Server", "Windows Server 2012");
        }
    }
}

 

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,