473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 2715
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Rodrigues | last post by:
Hi Everyone, I have been fighting a problem for a while and I wonder if someone out there can help. This problem has been presented in a number of news postings previously but I am yet to see a...
2
by: Dinkster | last post by:
BackGround: - We are new to ASP - We thought we would experiment with using the session object (in proc) to store a small amount of data. - We get different results when cookieless is set to...
2
by: David Popeck | last post by:
I have an ASP.NET application that is using forms authentication and I want to know when a session has timed out I have read quite a lot of posts here about this but no-one seems to have to same...
2
by: Ricky K. Rasmussen | last post by:
Hi NG, We have a rather large ASP.NET application that uses popups to display various dialogs to the user. In our work we've come over a rather annoying "bug": If we open a modal dialog using...
13
by: Alexander Widera | last post by:
hi, who has seen the follow problem or could help please? i visit a page .... i read a sesssion-var . ... everythink works...... i visit the page again..... error ... the sessionvar is null .... i...
3
by: catweezle2010 | last post by:
Hello NG, I have three files (default.aspx, search.aspx and work.aspx). The way is: login on default (if session is newsession). The loginname I write into as sessionvariable (username). So I...
4
by: Mark Rae | last post by:
Hi, I have a site which uses dynamic MasterPages. The selection of the MasterPage to use is determined by an encrypted QueryString. Session_Start looks for the presence of the QueryString,...
3
by: rsouza | last post by:
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...
4
by: Zhangming Su | last post by:
Hi, Can any one tell me why Session.IsNewSession doesn't work with Firwfox broswer? Z. Su
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.