Tuesday 15 March 2011

javascript - Controller action not redirect user is called from AJAX -



javascript - Controller action not redirect user is called from AJAX -

i have controller action purpose log off user. can achieved 2 ways:

first when user click on logout link on page looks this: <a href="/mayapp/account/logout">logout</a> works perfect.

second way when user in idle (do nil time). after time ajax phone call happened , phone call controller action in following:

$.ajax({ url: '/myapp/account/logout', type: 'get', success: function () { sessionstorage.removeitem('currenttime'); } })

problem because sec way doesn't work properly. phone call controller action controller action never redirect user login page. user logged off still remain on same page.

i using redirection in next way:

[allowanonymous] public actionresult logout() { // logic homecoming redirect(url.action("login", "account")); }

my questions are: happened if using asynchronous call?

i tried synchronous ajax phone call doesn't work.

how can phone call controller action in different way ajax?

thanks

try:

return redirecttoaction("login", "account");

edit

the problem because ajax phone call calling logout action, it's ajax phone call gets redirected. in mind perform client side redirect using window.location in javascript.

you utilize like:

return javascript("window.location = 'http://www.google.co.uk'");

or reload current page (so other routing kicks in user isn't authorised view page.

return javascript("location.reload(true)");

javascript ajax asp.net-mvc

No comments:

Post a Comment