Skip to content

Instantly share code, notes, and snippets.

@reinforchu
Created December 19, 2018 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinforchu/f9ec04ba3cf316c905f355b0e5134477 to your computer and use it in GitHub Desktop.
Save reinforchu/f9ec04ba3cf316c905f355b0e5134477 to your computer and use it in GitHub Desktop.
CustomHeader
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