Skip to content

Instantly share code, notes, and snippets.

@shawnmclean
Created April 29, 2012 18:55
Show Gist options
  • Save shawnmclean/2552652 to your computer and use it in GitHub Desktop.
Save shawnmclean/2552652 to your computer and use it in GitHub Desktop.
Setting Http Headers via attributes for ASP.NET Webapi
public class HttpHeaderAttribute : ActionFilterAttribute
{
/// <summary>
/// The name of the Http Header
/// </summary>
public string Name { get; set; }
/// <summary>
/// The value of the Http Header
/// </summary>
public string Value { get; set; }
/// <summary>
/// Set Http Headers in the response
/// </summary>
/// <param name="name">Name of the Http header</param>
/// <param name="value">Value of the Http header</param>
public HttpHeaderAttribute(string name, string value)
{
Name = name;
Value = value;
}
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
actionExecutedContext.Result.Headers.Add(Name,Value);
base.OnActionExecuted(actionExecutedContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment