3 Replies - 2824 Views - Last Post: 16 December 2008 - 08:06 PM Rate Topic: -----

#1 basslover  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-September 08

Session is not hitting timeout ?

Posted 16 December 2008 - 06:18 AM

Hii...

I'm newbie here. And I have some problem here.
I have a web project using ASP.NET and C# languange. For security reason, i want to make a Session for User Info after User has logged in.
I have no any experience dealing with Session before, So i make a simple project with session. And i have problem with my 'Session Timeout'.

Here is my code :

1. Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="btnSessionstart" runat="server" onclick="btnSessionstart_Click" Text="Start Session" /><br />
		<br />
		<asp:Button ID="btnCheck" runat="server" onclick="btnCheck_Click" Text="Check Session" />
	    <br />
		<asp:TextBox ID="txtSession" runat="server" Width="266px"></asp:TextBox><br />
		<br />
	</div>
	</form>
</body>
</html>



2. Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	protected void btnSessionstart_Click(object sender, EventArgs e)
	{
		Session["TEST"] = "ABCDE";
	}
	protected void btnCheck_Click(object sender, EventArgs e)
	{
		if (Session["TEST"] != null)
			txtSession.Text = Session["TEST"].ToString();
		else
			txtSession.Text = "Session has expired";
	}
}



3. Web.Config (this is where i set my Session Timeout)
<?xml version="1.0"?>
<configuration>
	<appSettings/>
	<connectionStrings/>
	<system.web>
		
		<compilation debug="true"/>
		
		<authentication mode="Forms"/>
		<sessionState mode="InProc" cookieless="false" timeout="1" />
		
						<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
							<error statusCode="403" redirect="NoAccess.htm" />
							<error statusCode="404" redirect="FileNotFound.htm" />
					   </customErrors>
	</system.web>
</configuration>



As you can see, I only have 3 components, 1 TextBox (txtSession) and 2 Buttons (btnSessionstart and btnCheck), and my Session timeout is 1 minutes (set in web.config file).

While running the project, first i click btnSessionstart to set the value of Session["TEST"] which is 'ABCDE'. And then i click btnCheck to insert 'ABCDE' into txtSession textbox (because Session["TEST"] is not null. Then, all i'm doing is clicking btnCheck every second for 1 minute in order to change the 'ABCDE' into 'Session has expired' because after 1 minute the the Session reach its timeout and set to null value. But, it never happen.

Am i having wrong concept of Session ? or What's wrong with my code ?

Thanks for any replies.

Best Regards,


Basslover,
Software Developer
Jakarta - Indonesia

This post has been edited by basslover: 16 December 2008 - 08:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Session is not hitting timeout ?

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Session is not hitting timeout ?

Posted 16 December 2008 - 08:56 AM

As long as you continue to access the session value by ID, then the time will be reset. So each time you test if it is null in the button click event it is resetting the timer.

Try waiting a minute before doing anything, then hit the button and the session will have expired.

Quote

A session is considered active as long as requests continue to be made with the same SessionID value. If the time between requests for a particular session exceeds the specified time-out value in minutes, the session is considered expired. Requests made with an expired SessionID value result in a new session.

Was This Post Helpful? 0
  • +
  • -

#3 basslover  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-September 08

Re: Session is not hitting timeout ?

Posted 16 December 2008 - 07:24 PM

View PostJayman, on 16 Dec, 2008 - 07:56 AM, said:

As long as you continue to access the session value by ID, then the time will be reset. So each time you test if it is null in the button click event it is resetting the timer.

Try waiting a minute before doing anything, then hit the button and the session will have expired.

Quote

A session is considered active as long as requests continue to be made with the same SessionID value. If the time between requests for a particular session exceeds the specified time-out value in minutes, the session is considered expired. Requests made with an expired SessionID value result in a new session.


Oh.. I see. Either GETS or SETS value on Session will reset the timer, am i right ?

Now, i learn new concept of Session. Thank u very much.

Best Regards,

Basslover
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Session is not hitting timeout ?

Posted 16 December 2008 - 08:06 PM

Yes, that is correct.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1