asp.net mvc - Preventing jQuery modal popup from opening on session timeout MVC4 -
i have asp.net mvc 4 application, in i'm trapping session timeout in session timeout filter handler handle session timeouts. want handle session timeout ajax requests. implemented code found in question here.
which worked treat autocompletes , other ajax calls, issue being ajax calls modal popups!
so have changed session timeout handler :
public override void onactionexecuting(actionexecutingcontext filtercontext) { if (filtercontext.httpcontext.session != null) { if (filtercontext.httpcontext.session.isnewsession) { var sessionstatedetails =(sessionstatesection)configurationmanager.getsection("system.web/sessionstate"); var sessioncookie = filtercontext.httpcontext.request.headers["cookie"]; if ((sessioncookie != null) && (sessioncookie.indexof(sessionstatedetails.cookiename) >= 0)) { if (filtercontext.httpcontext.request.isajaxrequest()) { filtercontext.httpcontext.response.clear(); filtercontext.httpcontext.response.statuscode = 500; i.e. setting status code 500 (401 didnt work me cause using windows authentication , impersonation if change status 401, security popup password , username).
and trap in either .ajaxsetup , or .ajaxerror have tried both ...and re-direct session timeout action (as required) display view session timeout.
$(document).ajaxerror(function (xhr, props) { if (props.status === 500) { ////session redirect goes here var patharray = window.location.pathname.split('/'); var segment_1 = patharray[1]; var newurl = window.location.protocol + "//" + window.location.host + "/" + segment_1 + "/home/sessiontimeout"; window.location = newurl; } }); the problem before re-direct , ajax popup still briefly opened. doesnt great. idea how can prevent opening @ , re-directing smoothly ?
here jquery dialog code:
$(document).ready(function () { $(".opendialog").live("click", function (e) { e.preventdefault(); $("<div></div>") .addclass("dialog") .attr("id", $(this) .attr("data-dialog-id")) .appendto("body") .dialog({ title: $(this).attr("data-dialog-title"), close: function () { $(this).remove() }, width: 600, modal: true, height: 'auto', show: 'fade', hide: 'fade', resizable: 'false' }) .load(this.href); }); $(".close").live("click", function (e) { e.preventdefault(); $(this).closest(".dialog").dialog("close"); }); }); any appreciated, think im there this.
i managed working in end , if else having same issue , here did ... kept using session handler , raise 403 instead of 500 , raising 500 wrong , had few undesirable side effects:
code
if (filtercontext.httpcontext.request.isajaxrequest()) { filtercontext.httpcontext.response.clear(); filtercontext.httpcontext.response.statuscode = 403; } else ...usual code goes here .... and trap ajax error follows:
$(document).ajaxerror(function (xhr, props) { if (props.status == 403 ) { ////session redirect goes here var patharray = window.location.pathname.split('/'); var segment_1 = patharray[1]; var newurl = window.location.protocol + "//" + window.location.host + "/" + segment_1 + "/home/sessiontimeout"; window.location = newurl; } }); of course popup still attempts load briefest of moments before re-direct ,but users dont seem mind.
Comments
Post a Comment