移除请求头中的语言标志

1: 移除X-AspNet-Version很简单,只需要在Web.config中增加这个配置节:
<system.web>
 <httpRuntime enableVersionHeader="false" />   //方法2经测试发现可以通过方法3删掉 和 HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
 </system.web>
 
 2:移除X-AspNetMvc-Version  在 Global.asax.cs 文件中加入
protected void Application_Start()
{
    MvcHandler.DisableMvcResponseHeader = true; //方法2经测试发现可以通过方法3删掉   和HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");等价
}

3:<configuration>
	<system.webServer>
		<modules>
			<add name="CustomHeaderModule" type="命名空间.CustomHeaderModule" />
		</modules>
		<httpProtocol>
		<customHeaders>
			<add name="X-Frame-Options" value="SAMEORIGIN"/>   //同一域充许iframe嵌套 具体可以查询
			<remove name="X-Powered-By"/>   //去掉这个标志
		</customHeaders>
		</httpProtocol>
		
		
	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");
            HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
            HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");

            HttpContext.Current.Response.Headers.Set("X-Powered-By", "PHP/7.1.8");//这里是为了迷惑敌人,只能通过上面的配置文件删除此标志
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值