开发者

Object reference error even when object is not null

i have an application wherein i have incorporate a "Remember Me" feature for the login screen. I do this by creating a cookie when the user logs in for the first time, so next time when the user visits the site i get the cookie and load the user information.

i have written the code for loading user information in a common class in the App_Code folder...and all my pages inherit from this class.

code for loading the user info is as follows:

public static void LoadUserDetails(string emailId)
{
    UsersEnt currentUser = UsersBL.LoadUserInfo(emailId);

    if (currentUser != null)
        HttpContext.Current.Session["CurrentUser"] = currentUser;
}

Now the problem is i get an "Object reference" error when i try to store the currentUser object in the session variable (even开发者_开发百科 though the currentUser object is not null). However the password property in the currentUser object is null.

Am i getting the error because of this...or is there some other reason??

thank you


Assuming it's the final line which is causing the problem, that suggests that either HttpContext.Current or HttpContext.Current.Session is null. I suggest you find out which it is, and then work out why.


HttpContext.Current.Session is probably null.

Code that uses the State has to be placed after the AcquireRequestState Event has called. See the page lifecycle for more information.

Try putting your code after or inside the Page_Load method.


If it is throwing the exception on the line:

HttpContext.Current.Session["CurrentUser"] = currentUser;

Then the only other explanation is that HttpContext.Current.Session is null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜