More in this section

Forums / Developing with Sitefinity / Setting session variables for persistently logged in users

Setting session variables for persistently logged in users

2 posts, 0 answered
  1. Erik
    Erik avatar
    10 posts
    Registered:
    01 Nov 2011
    21 Feb 2012
    Link to this post
    Hi all,

    I need to make sure that logged in users always have a custom object stored in the current session.

    It's obviously possible to create and fill the object at the moment a user logs in manually using a login control. But what if the user is already logged in persistently? What would be the best way to make sure that even they always get the object in the session?

    In other words, what happens when a persistently logged in user opens a new session? Is there a method that's being invoked which I can use to implement a session object check/insert in?

    Regards,

    Erik


  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    24 Feb 2012
    Link to this post
    Hi Erik,

    The ASP.NET Session_Start event that you can work with in Global.asax will fire once the current session starts, and will have a default timeout of 20 minutes. For more information you might check this article on MSDN. While the session is active, the Session_Start event will not get fired, so the only value you can store in that event is either on initial start of the session, or once it expires, and starts again. This looks like a convenient tool for the use case scenario you want to implement, so for example you can do:
    if (Request.QueryString["myQueryString"] != null )
     Session.Add("UserID", Request.QueryString["myQueryString"].ToString());
    and then retrieve this value wherever you need it, for example
    Response.Write(Session["UserID"]);
    On the other hand, if you need to set different querystring upon each request you might want to consider hooking up to Application_BeginRequest which gets fired every time a request is made.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered