C# Example to test Session Timeout

S

somoza.albert

Hello,

I'm trying to test out the change that I made in my config.web file in
C#. Basically, I've changed the timeout=1 for the session in
config.web, and want to test it out. I was told that you could set up
a button on a web page to create a session, and then another button to
check to see if the session was available after 1 minute, but I'm not
sure how to do this. Does anyone know how to do this, or another test
to ensure that the session will timeout after 1 minute?

Thanks
Albert.
 
S

Steven Nagy

Hi Albert,

As soon as someone hits a web page, a session is created for that
user, so no button is required.
You can however use a button to insert an item into the session
object. Then have another button that requests the value from
session.

Eg.

protected void button1_click(....) {
Session.Add("Test", textbox1.Text;
}

protected void button2_click(...) {
if (Session["Test"]==null) {
label1.Text = "The session expired";
}
else {
label1.Text = Session["Test"].ToString();
}
}


Also check out the Global.Asax.cs file for an event that will fire
when a session ends.

By the way, there are a lot of good resources on Session on the net
and in books, including the MSDN documentation at the Microsoft site.
Google is your friend.

Cheers,
Steven Nagy
 

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