Created
February 14, 2014 13:52
-
-
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.
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 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