Created
February 18, 2015 18:54
-
-
Save jamielittle/3a54ac64421b3eb2919f to your computer and use it in GitHub Desktop.
LoopbackAuthorisationFilter
This file contains 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 LoopbackAuthorisationFilter : System.Web.Http.Filters.AuthorizationFilterAttribute | |
{ | |
public override void OnAuthorization(HttpActionContext actionContext) | |
{ | |
// Play nicely with the base class :) | |
base.OnAuthorization(actionContext); | |
// If the request does not originate from this machine | |
if (!System.Web.HttpContext.Current.Request.IsLocal) | |
{ | |
// Create an Unauthorised Access response | |
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorised Access"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment