Thursday, December 20, 2007 - 文章

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.

搜尋

Go

<December 2007>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
 
RSS
【工商服務】
最新回應

Tags 分類檢視
關於作者

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

文章典藏
其他功能

這個部落格


BlogLook Score and Rank

Syndication