Session in .NET 2.0

Discussion in 'ASP .Net' started by Jack, Dec 26, 2007.

  1. Jack

    Jack Guest

    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.
     
    Jack, Dec 26, 2007
    #1
    1. Advertising

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

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


    "Jack" <> wrote in message
    news:uxL%23ad%...
    > 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.
    >
     
    Coskun SUNALI [MVP], Dec 26, 2007
    #2
    1. Advertising

  3. "Jack" <> wrote in message
    news:uxL%23ad%...

    > 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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Dec 26, 2007
    #3

  4. >> 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.
     
    Scott Roberts, Dec 26, 2007
    #4
  5. Read my article on codeproject for easy solution
    http://www.codeproject.com/KB/aspnet/SessionForever.aspx


    George.

    "Jack" <> wrote in message
    news:uxL%23ad%...
    > 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.
    >
     
    George Ter-Saakov, Dec 26, 2007
    #5
  6. 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$...
    > Read my article on codeproject for easy solution
    > http://www.codeproject.com/KB/aspnet/SessionForever.aspx
    >
    >
    > George.
    >
    > "Jack" <> wrote in message
    > news:uxL%23ad%...
    >> 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.
    >>

    >
    >
     
    Scott Roberts, Dec 26, 2007
    #6
  7. 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" <-webworks-software.com> wrote in
    message news:%23m3dO5$...
    > 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$...
    >> Read my article on codeproject for easy solution
    >> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
    >>
    >>
    >> George.
    >>
    >> "Jack" <> wrote in message
    >> news:uxL%23ad%...
    >>> 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.
    >>>

    >>
    >>

    >
     
    George Ter-Saakov, Dec 26, 2007
    #7

  8. > 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. :)
     
    Scott Roberts, Dec 26, 2007
    #8
  9. Jack

    LVP Guest

    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$...
    > Read my article on codeproject for easy solution
    > http://www.codeproject.com/KB/aspnet/SessionForever.aspx
    >
    >
    > George.
    >
    > "Jack" <> wrote in message
    > news:uxL%23ad%...
    >> 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.
    >>

    >
    >
     
    LVP, Dec 27, 2007
    #9
  10. 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:...
    > 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$...
    >> Read my article on codeproject for easy solution
    >> http://www.codeproject.com/KB/aspnet/SessionForever.aspx
    >>
    >>
    >> George.
    >>
    >> "Jack" <> wrote in message
    >> news:uxL%23ad%...
    >>> 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.
    >>>

    >>
    >>

    >
    >
     
    George Ter-Saakov, Dec 27, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Smythe
    Replies:
    3
    Views:
    1,325
    Jeff Smythe
    Jan 2, 2004
  2. Ed
    Replies:
    7
    Views:
    2,778
    Saravana [MVP]
    Feb 2, 2004
  3. jnickfl1
    Replies:
    0
    Views:
    631
    jnickfl1
    Sep 18, 2006
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,415
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Jazzis
    Replies:
    2
    Views:
    279
    Jazzis
    Sep 23, 2003
Loading...

Share This Page