2009-12-16 78 views

回答

2

試試這個:

private static new HttpSessionState Session 
    { 
     get { return HttpContext.Current.Session; } 
    } 

然後從另一個靜態函數你可以稱其爲

var myObj = Session[myKey]; 

就像你從常規的非靜態代碼會。

+0

+1這是一個非常好的主意 - 謝謝! – 2009-12-16 10:55:42

+0

我會給你這個創意的答案。 :) – 2009-12-16 10:56:19

2

這聽起來像你正在尋找: -

var sess = HttpContext.Current.Session; 
2

是的,Current財產上HttpContext是靜態的,因此:

System.Web.HttpContext.Current.Session 

會從靜態上下文返回當前會話(但你的必須在HTTP上下文內,否則Current將爲空)。

相關問題