Redirect Url In Case Of Session Out In Ajax

Hi,

I have a controller in which i use beforeAction where i do redirection to home page using $this->redirect(array(’/site/index’)), if session is expired. That is okay.

I have a function which contains some ajax stuff on click event. The problem is that if the session has timed out, It simply shows the home page within the div because of that redirection action, instead of redirecting the window to home page. I know it can be solved if we use javascript window.parent.location.href = ‘url’. But is there any other solutions for this in yii itself?

Thanks in advance

Hi,

Consider to use "accessControl" rules instead of checking a user inside beforeAction().

Also in this case you can set CWebUser::loginRequiredAjaxResponse which prevents redirecting to login

page during ajax requests.

Check http://www.yiiframework.com/wiki/321/using-loginrequiredajaxresponse-to-solve-ajax-session-timeout/

Thank you for your reply. However my ajax request function is in the same controller so that i can use the js window.location.href = ‘url’ in the beforeAction, because the above link finally says about that. Thank u again for your reply :)