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):
wrap ajax error event in dom ready function
$(document).ready(function () { $(document).ajaxerror(function (e, xhr, settings) { debugger; }); });
or check here
Comments
Post a Comment