asp.net mvc 3 - Ajax.BeginForm check if request was redirected -
how determine if async request form ajax form redirected? in case request redirected login page if user's session closed.
i tried check arguments of oncomplete, onsuccess , onbegin events (onfailure not called) no 1 helped.
currently have entire login page embaded in div of current page in case of session closing.
the way see how awoid - code this:
function onsuccesspost(a,b,c) { if (a.indexof("<!doctype html>") == 0) { window.location = window.location; } // ... }
but solution seems bit ugly.
any ideas?
don't redirect controller actions invoked through ajax. use json:
public actionresult foo() { var url = url.action("bar", "baz"); return json(new { location = url }, jsonrequestbehavior.allowget); }
and in ajax success callback:
success: function(result) { window.location.href = result.location; }
obviously if intend redirect client side after ajax request, kills benefit ajax. invoke controller action using standard link => it's meaningless use ajax in case.
update:
it seems trying intercept redirect logon page when forms authentication cookie has expired. phil haack blogged this: http://haacked.com/archive/2011/10/04/prevent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx
in article illustrates how prevent forms authentication module automatically redirect logon page instead send 401 status code intercepted ajax request , perform redirect on client.
Comments
Post a Comment