2

In my MVC app I have the following attribute that checks for logged on users:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
       ....
       if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
       {
               filterContext.Result = new Http403Result();
               filterContext.HttpContext.Response.StatusCode = 403;
       }
...
}

Layout.cshtml

    $("body").ajaxError(
        function (e, request, settings, exception) {
            alert('in');
            if (request.status == 403) {
                window.location = '@Url.Action("LogOn", "Account", new {area = "", msg = "forbidden", returnUrl = HttpContext.Current.Request.RawUrl})' + window.location.hash;
                return;
            }
            if (request.status == 500) {
                window.location = '@Url.Action("AccessDenied", "Error")';
                return;
            }
            if (request.status == 410) {
                window.location = '@Url.Action("Deleted", "Error")';
                return;
            }
            window.location = '@Url.Action("Index", "Error")';
        });

but for some reason alert("in") never gets hit even when 403 code is thrown (from ajax request):

enter image description here

0

1 Answer 1

4

Wrap the Ajax Error event in DOM Ready function

$(document).ready(function () {
    $(document).ajaxError(function (e, xhr, settings) {
        debugger;
    });
});

Or check here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.