몇 가지 추가 작업으로 System.Web.UI.Page 클래스를 확장하려고합니다. ctor에서 세션 변수의 값이 필요합니다.System.Web.UI.Page에서 상속하면 세션이 null입니다.
문제는 ... 내가로드 이벤트 모두에 세션 객체 부분을 이동하면
public class ExtendedPage : System.Web.UI.Page {
protected foo;
public ExtendedPage() {
this.foo = (int)HttpContext.Current.Session["foo"]; // NullReferenceException
}
}
... 세션 객체가 null이다 잘 작동
public class ExtendedPage : System.Web.UI.Page {
protected foo;
public ExtendedPage() {
this.Load += new EventHandler(ExtendedPage_Load);
}
void ExtendedPage_Load(object sender, EventArgs e) {
this.foo = (int)HttpContext.Current.Session["foo"];
}
}
왜 세션 객체가 null 첫 번째 경우에 ??
구성시 설정되지 않았지만 페이지로드 전에 설정된다는 것을 의미합니까? (전 사전 준비에서 생각합니다.) –
@ 스벤 : 맞아. – SLaks