ASP.NET Commander Page

Posted on 2005-05-09
Last Modified: 2010-04-07
I am in the process of building a commander page for my ASP.NET application.  

The commander page is a class that inherits "System.Web.UI.Page"

Then, on webforms within my application, rather than inheriting "System.Web.UI.Page" on the forms, I inherit my commander page.

This works great, up until I try to access Session variables from my commander class.

I've tried several variations, and I keep getting the following error:

"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive"

Keep in mind, that Session State is ENABLED, and works fine from other locations.  I think this has to do with an order in which the code is being executed but not quite sure.

Any help would be greatly appreciated.

Question by:mmarksbury
    LVL 33

    Expert Comment

    I do this all the time, and I've never ran into a problem with the session.  Can you post the source of this page?
    LVL 7

    Author Comment

    using System;
    using System.Data;
    using System.Configuration;

    namespace MyApp.BLL
          public abstract class AdminPage : System.Web.UI.Page
                private int      _UserId;
                public AdminPage()
                                                    _UserId = Convert.ToInt32(this.Session["UserId"]);
                      System.Web.UI.WebControls.Literal PL = new System.Web.UI.WebControls.Literal();
                      PL.Text = _UserId.ToString();
    LVL 33

    Accepted Solution

    You shouldn't be defining your own constructor in this page, rather you should use the normal events of the page lifecycle to do things.  For example, the code you have looks like it would be better placed in page_init.

    LVL 7

    Author Comment

    an example ?
    LVL 7

    Author Comment

    Nevermind, I got it.  Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now