#if NETFX using System; using System.Collections.Generic; using System.Web; namespace Apewer.Web { /// 通用 HTTP 模块。 internal class UniversalModule : IHttpModule { /// public void Dispose() { } /// 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(); 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