views:

206

answers:

1

Hi,

I've run in to a this problem regarding Sessions in asp.net. I'm creating an ASP.Net web application. I've created a class called BasePage that inherits from System.Web.Ui.Page. This BasePage class is a System.Web.Ui.Page with an additional member called ActiveUser of type ActiveUser (a class I've created of my own). In the constructor of BasePage I set the member ui to this.ui = (ActiveUser)Session["ActiveUser"], which is a session var that is previously set. However, when I run my project i get a HttpException in BasePage's constructor on this.ui = Session["ActiveUser"]. It tells me to check however enableSessionState is set to true in the config file, which I've checked that it is. Do anyone have any idéas on how to solve this one? It would be very much appreciated. Thanx!

+3  A: 

Just curious why are you saving this in the base page constructor?

You shouldn't be accessing the session from the constructor but the Page_Init instead. See the following post:

http://weblogs.asp.net/anasghanem/archive/2008/05/07/avoid-using-the-session-in-the-page-constructor.aspx

The session variable will be accessible at any time when implementing the page functionality so why not create a static class / method with functionality to grab all your session data? I don't see why you would want to duplicate storage of this data in your base class.

You might want to check out this thread: http://stackoverflow.com/questions/133236/asp-net-session

Kelsey
Thank's a lot for the advice. I folloes the proposed guire on weblogs.asp.net and it worked like magic!
Clean