VS2008-Session Exception Of Custom WebControl
I have an old custom webcontrol worked fine for years on VS 2005. When I edited a ASP.NET 2.0 web site project with VS 2008, tried to drag the .NET 2.0 webcontrol from toolbox to the web page, I got this exception in IDE.
"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."
Search for this issue via Google, most of the discussions focus on session not enabled or WSS issue. I am very sure the enableSessionState is enabled and no WSS issue in my web site. Will it be design time session issue?
I reviewed my code and found this:
protected override void OnInit(EventArgs e)
{
base.OnInit (e);
if (!Page.IsPostBack)
{
//Generate a unique key
Text=Guid.NewGuid().ToString("N").ToUpper();
//Store some variable to session
Page.Session[Text+"_State"]="Start";
}
}
Yeah, I use Session object in OnInit, maybe it's the cause. So the above code was modified as
if (!this.DesignMode)
Page.Session[Text+"_State"]="Start";
Now my custom webconrol get back again in VS2008, case closed.
[My Conclusion]
When Page.Session object is used during design time, VS2005 will ignore it, but VS2008 will throw an "session can not be used..." exception and cause a error desgin time display.