Skip to content

Instantly share code, notes, and snippets.

@feanz
Created November 21, 2013 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save feanz/7580416 to your computer and use it in GitHub Desktop.
Save feanz/7580416 to your computer and use it in GitHub Desktop.
MVC Application Version Filter
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class CurrentVersionHeaderAttribute : ActionFilterAttribute
{
private const string _xVersion = "X-Version";
private static readonly string _version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
var headers = filterContext.HttpContext.Response.Headers;
if (headers != null)
{
if (!headers.AllKeys.Contains(_xVersion))
{
headers.Add(_xVersion, _version);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment