Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Created January 14, 2014 15:46
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 rfaisal/8420404 to your computer and use it in GitHub Desktop.
Save rfaisal/8420404 to your computer and use it in GitHub Desktop.
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(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