jquery - Handling session timeout in ajax -


in mvc app have following attribute checks 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 reason alert("in") never gets hit when 403 code thrown (from ajax request):

enter image description here

wrap ajax error event in dom ready function

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

or check here


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -