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.


Comments

# by tony

错误 100 未能从程序集 PresentationBuildTasks, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 加载任务“Microsoft.Build.Tasks.Windows.GetWinFXPath”。未能加载文件或程序集“PresentationBuildTasks, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。系统找不到指定的文件。 确认 <UsingTask> 声明是正确的,并且该程序集及其所有依赖项都可用。 請各位解決一下?謝謝啦

Post a comment