Skip to content

Instantly share code, notes, and snippets.

@jamielittle
Created February 18, 2015 18:54
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 jamielittle/3a54ac64421b3eb2919f to your computer and use it in GitHub Desktop.
Save jamielittle/3a54ac64421b3eb2919f to your computer and use it in GitHub Desktop.
LoopbackAuthorisationFilter
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