Session in .NET 2.0

J

Jack

Hi,

I am new to .net. I have created a small web application using .net 2.0 in
vs2005, where the user logs in and adds content on their pages. The content
editing is done by integrating a wysiwyg editor (FCKEditor).

The problem is that sometime if the user spends too much time editing the
content and presses the update button, the session gets timed out and the
users looses all what he has been doing. In the old days of classic ASP, i
used to increase the Session.Timeout value to a high number. But how to do
it in .NET? I would like to know some best practice example of keeping the
user session alive in .NET.

Any help is appriciated.

Tnx.
 
C

Coskun SUNALI [MVP]

Hi,

You can achieve changing the timeout value in "web.config" file.

You have to find the node beginning with "sessionState" under "<system.web>"
node and change the value of "timeout" attribute. The value you set here is
based on "minute"s. So if its value is "20" then your session timeout value
is 20 minutes.
 
M

Mark Rae [MVP]

In the old days of classic ASP, I used to increase the Session.Timeout
value to a high number. But how to do it in .NET?

Same way:
http://msdn2.microsoft.com/en-us/li...ionstate.httpsessionstate.timeout(VS.80).aspx
I would like to know some best practice example of keeping the user
session alive in .NET.

Sessions time out for a reason, namely to reduce the amount of memory
overhead on the webserver. As the MSDN article below states, you should
really think very carefully before increasing the timeout value...
http://msdn2.microsoft.com/en-us/library/ms525473.aspx
 
S

Scott Roberts

Sessions time out for a reason, namely to reduce the amount of memory
overhead on the webserver. As the MSDN article below states, you should
really think very carefully before increasing the timeout value...
http://msdn2.microsoft.com/en-us/library/ms525473.aspx

I'll second that. IMO, the "best practice" for using sessions is to pass
data from one page to another on a redirect. If you need to persist data
longer than a couple of seconds, I'd put it in a DB.
 
S

Scott Roberts

Nice work-around, but you still can't control when the asp.net worker
process re-cycles. Especially in a shared host environment.
 
G

George Ter-Saakov

Ideally it should never recycle.
If you have a browser hitting the SessionRenew.aspx every 10 minutes then it
will not recycle due to inactivity.

If it recycles just because someone spiked CPU and hoster had to hit reset
button in shared hosting environment you doomed no matter what you do :)

But then if availability that important to you time to think about dedicated
server.

George.
 
S

Scott Roberts

Ideally it should never recycle.

It does.
If you have a browser hitting the SessionRenew.aspx every 10 minutes then
it will not recycle due to inactivity.

Probably due to memory - from other hacks stuffing too much crap in their
session variables.
If it recycles just because someone spiked CPU and hoster had to hit reset
button in shared hosting environment you doomed no matter what you do :)
Indeed.

But then if availability that important to you time to think about
dedicated server.

Or not use sessions. :)
 
L

LVP

George Ter-Saakov,

quick question:

why can't you use a gif image instead of the gif-class something like:

.......
.......
document.images("renewSession").src = "/images/spacer.gif?par=" +
Math.random();
.......
.......


Does this work? or Not ?

LVP
 
G

George Ter-Saakov

The whole point of it was to silently renew .NET Session. For that you must
hit something that goes through .NET engine (usually .aspx page) every 20
minutes or your session will expire and removed due to inactivity and to
preserve server resources.


So how hitting spacer.gif is going to help?
The request does not go through .NET and will not renew session.

George.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top