Can't use Session in Page base class property

A

Axel Dahmen

Hi,

I've added a property to my Page base class (this base class inherits from
Page and all my aspx.cs classes inherit from my base class). This property
of mine uses the Session object to determine its return information.

After implementing this property, whenever I now open any aspx page in the
Visual Studio 7.0 IDE, the following error shows up:

"The file failed to load in the Web form designer. Please correct the
following error, then load it again: Property accessor 'myProp' on object
'myPage' threw the following exception: 'Session state can only be used when
enableSessionState is set to true, either in configuration file or in the
Page directive'"

I've read some older newsgroup articles from Google
(http://groups.google.de/groups?q=EnableSessionState+property+Session+design
er&ie=UTF-8), but none contained helpful tips.

In fact my configuration is perfectly alright. Adding "EnableSessionState"
to the Page directive doesn't help and seems unnecessary to me anyway as
'true' is the default for that parameter.

It appears to be a Visual Studio quirk, doesn't it?

TIA,
Axel Dahmen


Here's an example of some implementation like mine:

public class myPage : System.Web.UI.Page
{
public string myProp {get {return
Session["anything"].ToString();}}
}
 
S

Scott Allen

Hi Axel:

The Designer is creating an instance of the page and inspecting the
properties during design time, but the Session collection is not
available.

There are a couple solutions:

1) Add a [Browsable(false)] attribute to the property so the property
browser doesn't try to inspect the property at design time.

2) Check if Page.Context is null. If Context is null then there is no
web request underway and Session state is not available.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top