Created
April 30, 2013 15:42
-
-
Save ajtowf/5489558 to your computer and use it in GitHub Desktop.
WebApi VersioningFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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