Hi Alberto,
you're doing this completely the wrong way.
On every page, browse and form, advanced tab, is an option
"must be logged in". If you tick this on, and the control is called as a page, then it will automatically redirect to the login screen.
If the control is _embedded_ on a page, then the control will be excluded, and no redirect will happen.
To know if a session is logged in use p_web.GetSessionLoggedIn()
Cheers
Bruce