Skip to content

Instantly share code, notes, and snippets.

@ajtowf
Created April 30, 2013 15:42
Show Gist options
  • Save ajtowf/5489558 to your computer and use it in GitHub Desktop.
Save ajtowf/5489558 to your computer and use it in GitHub Desktop.
WebApi VersioningFilter
public class VersioningFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var acceptHeaderContents = ...;
if (string.IsNullOrWhiteSpace(acceptHeaderContents))
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "No accept header provided");
}
else if (!IsCompatibleRequestVersion(acceptHeaderContents))
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Incompatible client version");
}
else
{
base.OnActionExecuting(actionContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment