+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Using ASP.NET Session

Using ASP.NET Session

8 posts, 0 answered
  1. Roger Cooper
    Roger Cooper avatar
    4 posts
    Registered:
    14 Aug 2009
    05 Oct 2009
    Link to this post
    I have a control that appears on multiple pages. I am attempting to save data in a session object when the control executes on one page so the saved data can be referenced when the control executes on other pages. It appears that a new ASP.NET session starts each time a page displays, so I am not having any luck passing data to other pages this way.

    Am I correct that each page creates a new session? If so, is there a setting that will allow me to change that? Do I have to use a permanent cookie to share data among pages?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Oct 2009
    Link to this post
    Hi Roger Cooper,

    Session state is scoped to the current browser session. Generally you have a session timeout period after which the data is lost and a new session is created. The session object is available yo any page. You can store many variables in the Session and they can be of any type.  When you store a variable in the Session, and you want to retrieve it back you should use the same key value( for instance after calling Response.Redirect).

    example

    PageOne.aspx


    Session["UserName"] = UserName.Text; 
    Response.Redirect("PageTwo.aspx");  

    PageTwo.aspx

    UserName.Text = Session["UserName"].ToString();   

    Another option is using QueryString or cookies.


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Paul
    Paul avatar
    1 posts
    Registered:
    23 Jun 2009
    05 Oct 2009
    Link to this post
    I work with Roger. He wasn't able to log in just now so I'm posting this.

    We know how to use a session variable. What we have found is we cannot use them in Sitefinity because the session keeps getting reset every time there is a new page. So the variables do not have the values we put in them, because they are associated with a new session ID. This is either a very big bug in Sitefinity or something basic about the implementation that we don't understand, perhaps some option that causes this behavior.
  4. Roger Cooper
    Roger Cooper avatar
    4 posts
    Registered:
    14 Aug 2009
    06 Oct 2009
    Link to this post
    I am well aware of what sessions are and how they are used. Using code in the control that appears on multiple pages, I have logged session IDs as users moved through my site. I found that the session ID changes for each page display. Sometimes I get one session ID to display a page and another session ID to handle a postback for a button click. This is making it impossible to use session variables to share data among the pages on my site.

    Is it normal for Sitefinity to create a new session each time a page is displayed? If so, is there some way I can change that behavior?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Oct 2009
    Link to this post
    Hi Roger Cooper,

    We sent a reply to your support requests.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Roger Cooper
    Roger Cooper avatar
    4 posts
    Registered:
    14 Aug 2009
    07 Oct 2009
    Link to this post
    Further testing on multiple machines showed that we were having problems in one environment but not others. We no longer believe that this could be a Sitefinity issue. Thank you.
  7. Lorenzo
    Lorenzo avatar
    4 posts
    Registered:
    07 Jul 2009
    05 Feb 2011
    Link to this post
    Hi Roger,
    I'm experiencing a very similar situation and although I'm pretty sure is not totally a Sitefinity concern could you please suggest me what was the cause of the problem you encountered and how did you solve it ?

    Thanks

    Lorenzo
     
  8. Roger Cooper
    Roger Cooper avatar
    4 posts
    Registered:
    14 Aug 2009
    07 Feb 2011
    Link to this post
    It has been long enough that I cannot remember exactly what we changed, though I recall changing IIS settings for State Management (a tab under ASP.Net Configuration Settings). We experimented with using StateServer for awhile. However, we are currently using Session State Mode = InProc, Cookieless Mode = UseCookies, and Session timeout = 20. I believe those are the defaults, though it appeared we had someone "helping" us by changing settings in one environment.
Register for webinar
8 posts, 0 answered