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.

歡迎推文分享:
Published 20 December 2007 12:30 PM 由 Jeffrey
Filed under: , , ,
Views: 9,007



意見

# tony said on 12 June, 2010 04:59 AM

错误 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> 声明是正确的,并且该程序集及其所有依赖项都可用。 請各位解決一下?謝謝啦

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 
(提醒: 因快取機制,您的留言幾分鐘後才會顯示在網站,請耐心稍候)

5 + 3 =

搜尋

Go

<December 2007>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
 
RSS
創用 CC 授權條款
【廣告】
twMVC
最新回應

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


Syndication