471,570 Members | 970 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Problems with Session.IsNewSession - please help

Hi.

Recently here in my work we added the following code in the Global.asax
file to handled the session expired and redirect users to the home of
the site explaining them the occurred (some thing like "Your session
has expired, please restart your navigation.").

public void Session_Start(Object sender, EventArgs e) {

if(Session.IsNewSession && Request.Headers["Cookie"] != null &&
Request.Headers["Cookie"].IndexOf("ASP.NET_SessionId") >= 0)
{
Response.Redirect("/index.aspx?timeout=1");
// when the param "timeout" exists in the url the user
receives the message "... Session expired ..."
}
}

In our tests the code above works fine, but now sometimes we open the
browser, type the url address of the site and the message "... session
expired ..." appears. This occurs just in some machines and not all the
times we access the site.

Someone knows what is happening??

Thanks

Rodrigo

Dec 14 '06 #1
2 2597
This is completely off the top of my head, so I may be way out.

Firstly, I'm not sure that this is best way of achieving what you seem to be
after. What we do is to check for session timeouts in the page load event
on each page of our applications (using Session.IsNewSession()). If it's a
new session, we set a flag (either in a custom object, or in the Session)
and redirect the user to the login page, which checks for the existence of
the flag.

Looking at your code, you need to check each element in your if statement to
see why all of them are true.

It appears to me that Session.IsNewSession will always be true in the
Session_Start event handler. If the Session wasn't new, it presumably
wouldn't be starting. So your problem, if you must use the Session_Start
event, really is in knowing why the other two conditions are true.

But as I said, this is right off the top of my head.
Peter

"rsouza" <ro********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi.

Recently here in my work we added the following code in the Global.asax
file to handled the session expired and redirect users to the home of
the site explaining them the occurred (some thing like "Your session
has expired, please restart your navigation.").

public void Session_Start(Object sender, EventArgs e) {

if(Session.IsNewSession && Request.Headers["Cookie"] != null &&
Request.Headers["Cookie"].IndexOf("ASP.NET_SessionId") >= 0)
{
Response.Redirect("/index.aspx?timeout=1");
// when the param "timeout" exists in the url the user
receives the message "... Session expired ..."
}
}

In our tests the code above works fine, but now sometimes we open the
browser, type the url address of the site and the message "... session
expired ..." appears. This occurs just in some machines and not all the
times we access the site.

Someone knows what is happening??

Thanks

Rodrigo

Dec 14 '06 #2
"rsouza" <ro********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Someone knows what is happening??
Get rid of the check for the cookie - it's not necessary.
Dec 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mark Rodrigues | last post: by
2 posts views Thread by Dinkster | last post: by
2 posts views Thread by David Popeck | last post: by
2 posts views Thread by Ricky K. Rasmussen | last post: by
13 posts views Thread by Alexander Widera | last post: by
3 posts views Thread by catweezle2010 | last post: by
4 posts views Thread by Mark Rae | last post: by
4 posts views Thread by Zhangming Su | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.