Skip to content

Instantly share code, notes, and snippets.

@Injac
Created February 14, 2014 13:52
Show Gist options
  • Save Injac/9001332 to your computer and use it in GitHub Desktop.
Save Injac/9001332 to your computer and use it in GitHub Desktop.
Web API based HTTPS Authorization Filter Attribute. Put that attribute on your Web API controller class.
public class RequireHttpsWebApiAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
}
else
{
base.OnAuthorization(actionContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment