You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
#if NETFX
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
|
|
namespace Apewer.Web
|
|
{
|
|
|
|
/// <summary>通用 HTTP 模块。</summary>
|
|
internal class UniversalModule : IHttpModule
|
|
{
|
|
|
|
/// <summary></summary>
|
|
public void Dispose() { }
|
|
|
|
/// <summary></summary>
|
|
public void Init(HttpApplication context)
|
|
{
|
|
context.PreSendRequestHeaders += new EventHandler(ByContext);
|
|
}
|
|
|
|
void ByContext(object sender, EventArgs e)
|
|
{
|
|
var context = HttpContext.Current;
|
|
if (context == null) return;
|
|
|
|
var keys = new List<string>();
|
|
keys.AddRange(context.Response.Headers.AllKeys);
|
|
if (keys.Contains("Server")) context.Response.Headers.Remove("Server");
|
|
if (keys.Contains("X-Powered-By")) context.Response.Headers.Remove("X-Powered-By");
|
|
}
|
|
|
|
void ByApplication(object sender, EventArgs e)
|
|
{
|
|
var app = sender as HttpApplication;
|
|
if (app == null) return;
|
|
if (app.Request == null) return;
|
|
if (app.Request.IsLocal == false) return;
|
|
if (app.Context == null) return;
|
|
if (app.Context.Response == null) return;
|
|
if (app.Context.Response.Headers == null) return;
|
|
var headers = app.Context.Response.Headers;
|
|
app.Context.Response.Headers.Remove("Server");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|