当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.Net自定义重写Http Server标头

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

2018年03月29日  | 移动技术网IT编程  | 我要评论

站立瑜伽,李延宗,英汉互译翻译器

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");
        }
    }
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网