Session not initialized?

Last post 11-19-2008 3:50 AM by Saturday3AM. 1 replies.

Sort Posts:

  • Session not initialized?

    11-18-2008, 6:28 PM
    • Member
      75 point Member
    • Saturday3AM
    • Member since 12-16-2007, 9:29 AM
    • N
    • Posts 139

    I have a base class BasePage which inherits Page in which I want to get the value of a Session containing the ID of the logged in member and make it accessible to all pages that inherits BasePage through a property called MemberId. This is so I don't have to check that the session is not null and has a value every time I need to check if the member is logged in and get his/her ID. I can simply check if MemberId is 0 (not logged in) or anything else (logged in).

    The problem is I use the urlrewriting.net component and on those pages that the url is rewritten on I get the error "Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.". If I go to the same page without the rewritten url I don't get the error.

    I think I have narrowed it down to the Session not being initialized at the time I'm trying to use it. I found this thread and they seem to have the same problem but they were trying to use a Session in the constructor which I'm not but the problem might still be similar.

    The component is probably messing something up. Any ideas why? How could I change the structure to get around this? Is there a way to force it to initialize earlier (if that is the problem)?

     

    1        public class BasePage : Page
    2 {
    3 public int MemberId
    4 {
    5 get { return (Session["id"] != null ? Convert.ToInt32(Session["id"]) : 0); }
    6 set { Session["id"] = value; }
    7 }
    8
    9 protected override void OnInit(EventArgs e)
    10 {
    11 MemberId = 1; // test
    12
    13 base.OnInit(e);
    14 }
    15
    16 protected override void OnLoad(EventArgs e)
    17 {
    18 base.OnLoad(e);
    19 }
    20 }
     

  • Re: Session not initialized?

    11-19-2008, 3:50 AM
    Answer
    • Member
      75 point Member
    • Saturday3AM
    • Member since 12-16-2007, 9:29 AM
    • N
    • Posts 139

    http://forums.asp.net/t/1349928.aspx

Page 1 of 1 (2 items)