2009-08-26 11 views

答えて

1

あなたはここでは、このような何か(擬似コード)

XmlDocument document = new XmlDocument(); 
document.Load("Web.Config"); 

XmlNode pagesenableSessionState = document.SelectSingleNode("//Settings[@Name = 'pages']/Setting[@key='enableSessionState']"); 

if(pagesenableSessionState .Attributes["value"].Value =="true) 
{ 
//Sessions are enabled 
} 
else 
{ 
//Sessions are not enabled 
} 
+0

セッションステートは、ページディレクティブと他の構成ファイル(上位ディレクトリレベルのmachine.configまたはweb.config)で有効にすることができるため、この回答は少なくとも不完全であり、最悪の場合は間違っています。 – wensveen

3

あなたがHttpContext.Currentを使用する場合は、例外を取得することはできません。

if(HttpContext.Current.Session != null) 
{ 
    // Session! 
} 
+1

このスローと例外です。 –

1

を使用することができますは、セッション状態が有効になっているかどうかを判断することができる方法であります:

PagesSection pagesSection = ConfigurationManager.GetSection("system.web/pages") as PagesSection; 

if ((null != pagesSection) && (pagesSection.EnableSessionState == PagesEnableSessionState.True)) 
    // Session state is enabled 
else 
    // Session state is disabled (or readonly) 
関連する問題