gpt4 book ai didi

c# - 访问 session 对象

转载 作者:太空宇宙 更新时间:2023-11-03 18:40:04 25 4
gpt4 key购买 nike

为什么在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com