Redirect to login page on timeout

A

Anders Jacobsen

Hey

Im devloping an application in asp.net 1.1 SP2. I need to control timeout
values for each user. Im having trouble to make it work. When the session
timouts out I want to redirect the user to the login page. OK.,

Im aware that we have 2 timeouts. Session timeout and forms authentication
timeout.

In login i do this
---------------
Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
_username,
DateTime.Now,
DateTime.Now.AddMinutes(20), <<<<< HOW DO I CHANGE THIS VALUE WHILE USER
LOGED ON?
false,
_userid.ToString(),
FormsAuthentication.FormsCookiePath )
;
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpContext.Current.Response.Cookies.Add(
new HttpCookie(
FormsAuthentication.FormsCookieName,
encryptedTicket)
);

HttpContext.Current.Session["TimeoutVar"] = "";`
--------------

I have never gotten this to work so I tried to use the Session to control
this and tried something like this.
----------------
protected void Application_OnAcquireRequestState(Object sender, EventArgs e)
{
if( User.Identity != null && User.Identity.IsAuthenticated &&
Session["TimeoutVar"] == null )
{
FormsAuthentication.SignOut();
this.Response.Redirect(this.Request.ApplicationPath + "/Default.aspx");
}
}
---------------

And in a derrived page template
----------------
override protected void OnInit(EventArgs e)
{
base.OnInit(e);

if(User.Identity.IsAuthenticated)
{
if(Session.Timeout != (Context.User.Identity as
UserIdentity).User.Timeout)
{
Session.Timeout = (Context.User.Identity as UserIdentity).User.Timeout;

} } }}

This works...Sometimes. But it randomly enter the IF clause in
OnAcquireRequestState and gets redirected. It varys alot from seconds but
sometimes servereal mintues.

Anyway. How is the "CORRECT" way to implement functionality that can set;
from user to user; logout interval.when using forms autentication.

NB: Session is inproc and set to 20 min in web.config (but is instantly
overriden by the codebehind reassign)

Thanks in regards
Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top