Skip to content

Instantly share code, notes, and snippets.

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 LSTANCZYK/91bb5a323ef88d1d57cf691473f3c0ad to your computer and use it in GitHub Desktop.
Save LSTANCZYK/91bb5a323ef88d1d57cf691473f3c0ad 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