Skip to content

Instantly share code, notes, and snippets.

@house9
Created April 22, 2011 15:17
Show Gist options
  • Save house9/936865 to your computer and use it in GitHub Desktop.
Save house9/936865 to your computer and use it in GitHub Desktop.
AuthorizeForAttribute.cs
public class AuthorizeForAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if(filterContext.HttpContext.Request.IsAjaxRequest())
{
// filterContext.Result = new HttpStatusCodeResult(401, "Unauthorized");
filterContext.Result = new HttpStatusCodeResult(403, "Forbidden");
}
else if(filterContext.HttpContext.User.Identity.IsAuthenticated)
{
filterContext.Result = new RedirectResult("~/Error/AccessDenied?For=" + filterContext.HttpContext.Request.Url);
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment