2

i have a cs class file in a web project in vs 2010. in class,i read and wirte session variables. but my Session property is null!

i use this:

 public static int UserID
        {
            get
            {
                if (HttpContext.Current.Session["UserID"] == null) return 0;
                return int.Parse(HttpContext.Current.Session["UserID"].ToString());
            }
            set
            {
                HttpContext.Current.Session["UserID"] = value;
            }

        }

but my HttpContext.Current.Session is null(no HttpContext.Current.Session["x"])

note web project has no App_Code folder.

how to use session in my class?

4

1 回答 1

0

因为您的财产是静态的,而 Sessions 不是静态的。所以你不能访问它。

有关更多信息,请参阅以下链接: MSDN

于 2016-07-23T08:16:41.537 回答