How I can stop executing action/controller without redirection, and only return Response with statusCode
public class MainAuthorizationFilter : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
... [my Authorization login] ...
if([Authorization fail])
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.HttpContext.Response.StatusCode = 401;
// HERE I want stop executing action/controller because I want return only statusCode
}
else
{
// In non-ajax request I just redirect me request and action/contoller isn't executed
filterContext.Result = new RedirectToRouteResult("Error", new RouteValueDictionary { { "errorCode", errorCode } });
}
}
}
base.OnAuthorization(filterContext);
}
[MainAuthorizationFilter]
public ActionResult CreateFolder(...)
{
CreateFolder(...);
}
filterContext.Result = new HttpStatusCodeResult(401, "String description here if you want");
HttpStatusCodeResult
on MSDN
Note that the forms auth module may intercept this and convert it to a redirect to your login page - not sure if this applies to AJAX requests too, I haven't tried it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With