Session在一个页面是System.Web.UI.Page.Session.由于您的页面派生自Page类,因此您可以在没有限定条件的情况下引用它.
你的课可能不是来自Page.
在你的课堂上,请HttpContext.Current.Session改用.
布莱恩提出了一个很好的观点.通常,您的类代码可能不会在请求的上下文中被调用.始终先检查:
if (HttpContext.Current != null)
{
if (HttpContext.Current.Session != null)
{
object cell = HttpContext.Current.Session["variable"];
if (cell != null)
{
return (int) cell; // Or whatever
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |