Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SignInRequired : ActionFilterAttribute
- {
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- // User is verified, continue executing action
- if (Acme.Web.CurrentUser != null)
- {
- return;
- }
- // End response with 401 Unauthorized
- var response = HttpContext.Current.Response;
- response.StatusCode = (int)HttpStatusCode.Unauthorized;
- response.End();
- // Prevent the action from actually being executed
- filterContext.Result = new EmptyResult();
- }
- }
- public class SignInRequiredAttribute : AuthorizeAttribute
- {
- protected override bool AuthorizeCore(HttpContextBase httpContext)
- {
- return !Acme.Web.CurrentUser != null;
- }
- }
- public override void OnActionExecuting(HttpActionContext actionContext)
- {
- actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
- }
- filterContext.Result = new RedirectResult("~/Error/Unauthorized");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement