Created
December 19, 2018 10:38
-
-
Save reinforchu/f9ec04ba3cf316c905f355b0e5134477 to your computer and use it in GitHub Desktop.
CustomHeader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
namespace CustomHeader | |
{ | |
/// <summary> | |
/// Add Custom Header | |
/// </summary> | |
public class Class1 : IHttpModule | |
{ | |
private HttpApplication App; | |
private string HttpResponseBody; | |
public void Init(HttpApplication context) | |
{ | |
App = context; | |
context.PreSendRequestHeaders += new EventHandler(OnPreSendRequestHeaders); | |
} | |
private void OnPreSendRequestHeaders(object sender, EventArgs e) | |
{ | |
SetProductBanner(); // Add product header | |
} | |
public void SetProductBanner() | |
{ | |
AddHeader("X-Powered-By", AssemblyInformation.Name + "/" + AssemblyInformation.Version); | |
} | |
public class AssemblyInformation | |
{ | |
public static readonly string Name = "CustomHeader"; | |
public static readonly string Release = "Beta"; | |
public static readonly string Version = "1.0.0.0"; | |
} | |
private void AddHeader(string field, string value) | |
{ | |
HttpContext.Current.Response.Headers.Add(field, value); | |
} | |
public void Dispose() | |
{ | |
HttpResponseBody = String.Empty; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment