为什么在System.Web.UI.Page实例的Page_Load方法中可以访问到Session对象,在其他地方却不行?
public partial class Statystyki : System.Web.UI.Page
{
// Session object not allowed here
protected void Page_Load (object sender, EventArgs e)
{
// but allowed here
}
}
而且在自定义类中是不允许的。如何从自己的类中获取对该对象的引用?
最佳答案
您可以像这样在自定义类中访问它
HttpContext.Current.Session["Key"]
关于c# - 访问 session 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899637/