Session problem with ASPX

G

Guest

Hi,

I am a programmer and I have a question about a ASP.NET peace of code.

I have a program that has a session timeout of 2 minutes configured in
Web.config file:

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data
source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="2"
/>

In the code behind of my Main.aspx I have this C# peace of code:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">");
// Retreaves the current user
// the user has been created in the Session_Start() of Global.asax
with the SQLServer connection
user = (Usager)Session[ "User" ];
if (IsPostBack)
{
// Retreives the department list from the session instead of the SQL
connection
arrayDept = (ArrayList)Session[ "ArrayDept" ];
}
else // Initial Load
{
arrayDept = new ArrayList();
DisplayDepartments();
LoadCustomers();
}
// Validate if the session has expired
if (arrayDept == null)
{
Response.Write( "Your Session as expired. Please close your browser
and relog to the site."
Response.Write("<SCRIPT
language=javascript>window.close();</SCRIPT>");
Response.End();
}
else
{
// Create an adapter and populate the dataset
CreateAdapter();
LoadDataSet();
ManageAccessRights();
}
}

Now if I load this site, wait 2 minutes and click somewhere on the page, the
“Your session as expired…†message appears. Since in trying to force the IE
window to close I get the standard “the Web page you are viewing is trying to
close the window. Do you want to close the window?†message. Is chose NO.
Then I click the IE BACK button, do a REFRESH, click yes to the standard
“...you must resend the information…†message and I get back to the exact
page where I was with my session reactivated.

I’m an old fashion ASP expert but I’m kind of new with this ASP.NET thing.
I’ve been struggling with this problem for a couple of days now.

Do you have any idea what may be the cause of this problem?

Thanks.
 
M

Marina Levit [MVP]

When you refresh the original page, then that is not a postback (because
this is just a GET). That reloads the array. So the page looks just like it
did when you browsed to the page the first time.

At least this is my understanding of what you are doing.
 
M

Marina Levit [MVP]

You can test Session.IsNewSession to see if this session has just been
started with the current request.
 

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

Top