2013-05-19 4 views
2

나는 2010 년 대 웹 프로젝트에서 cs 클래스 파일을 가지고 있습니다. 클래스에서 읽기 및 세션 변수를 읽었습니다. 내 세션 속성이 null입니다.cs 클래스 파일의 세션이 null 인 이유는 무엇입니까? (웹 프로젝트 .net 2010)

나는이 사용

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; 
      } 

     } 

을하지만 내 HttpContext.Current.Session는 (더 HttpContext.Current.Session [ "X"])

노트 웹 프로젝트가 어떤을 App_Code가 없습니다 널 (null)입니다 폴더.

내 수업에서 세션을 사용하는 방법은 무엇입니까?

답변

1

속성이 정적이고 세션이 정적이 아니기 때문에 그래서 액세스 할 수 없습니다. 에 MSDN

+0

참조 : http://stackoverflow.com/questions/2577183/how-can-i-get-the-value-of-a-session-

더 informaton은 아래 링크를 참조하십시오 static-inside-a-static-method –