Session in .NET 2.0

Session in .NET 2.0

am 26.12.2007 18:47:02 von Fabri

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.

Re: Session in .NET 2.0

am 26.12.2007 18:52:01 von Coskun

Hi,

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

You have to find the node beginning with "sessionState" under ""
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.

--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com


"Jack" wrote in message
news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
> 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.
>

Re: Session in .NET 2.0

am 26.12.2007 18:54:26 von mark

"Jack" wrote in message
news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...

> 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/library/system.web.sessions tate.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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Session in .NET 2.0

am 26.12.2007 20:01:56 von Scott Roberts

>> 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

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.

Re: Session in .NET 2.0

am 26.12.2007 20:59:54 von George Ter-Saakov

Read my article on codeproject for easy solution
http://www.codeproject.com/KB/aspnet/SessionForever.aspx


George.

"Jack" wrote in message
news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
> 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.
>

Re: Session in .NET 2.0

am 26.12.2007 21:31:36 von 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.



"George Ter-Saakov" wrote in message
news:%23OoRjn$RIHA.5360@TK2MSFTNGP03.phx.gbl...
> Read my article on codeproject for easy solution
> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
>
>
> George.
>
> "Jack" wrote in message
> news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
>> 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.
>>
>
>

Re: Session in .NET 2.0

am 26.12.2007 21:42:26 von 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.

"Scott Roberts" wrote in
message news:%23m3dO5$RIHA.536@TK2MSFTNGP06.phx.gbl...
> Nice work-around, but you still can't control when the asp.net worker
> process re-cycles. Especially in a shared host environment.
>
>
>
> "George Ter-Saakov" wrote in message
> news:%23OoRjn$RIHA.5360@TK2MSFTNGP03.phx.gbl...
>> Read my article on codeproject for easy solution
>> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
>>
>>
>> George.
>>
>> "Jack" wrote in message
>> news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
>>> 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.
>>>
>>
>>
>

Re: Session in .NET 2.0

am 26.12.2007 21:54:07 von 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. :)

Re: Session in .NET 2.0

am 27.12.2007 02:04:54 von 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




"George Ter-Saakov" wrote in message
news:%23OoRjn$RIHA.5360@TK2MSFTNGP03.phx.gbl...
> Read my article on codeproject for easy solution
> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
>
>
> George.
>
> "Jack" wrote in message
> news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
>> 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.
>>
>
>

Re: Session in .NET 2.0

am 27.12.2007 16:35:34 von 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.

"LVP" wrote in message
news:OMNNASCSIHA.5976@TK2MSFTNGP05.phx.gbl...
> 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
>
>
>
>
> "George Ter-Saakov" wrote in message
> news:%23OoRjn$RIHA.5360@TK2MSFTNGP03.phx.gbl...
>> Read my article on codeproject for easy solution
>> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
>>
>>
>> George.
>>
>> "Jack" wrote in message
>> news:uxL%23ad%23RIHA.2000@TK2MSFTNGP05.phx.gbl...
>>> 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.
>>>
>>
>>
>
>