Click here to Skip to main content
16,012,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using membership class to validate user(user name="Guest",Password="guest",this user exist in database) by calling validate() method.i m posting code what i did in my project to explain well my question:

C#
private void Page_Init(object sender, EventArgs e)
{
            MembershipUser user;
            if (!User.Identity.IsAuthenticated)
            {
                Membership.ValidateUser("Guest","guest");
                FormsAuthentication.SetAuthCookie("Guest", false);
                user = Membership.GetUser("Guest");
               var b=Context.User.Identity.Name;
                
            }
}
 protected void Page_Load(object sender, EventArgs e)
{

  MembershipUser user=Membership.GetUser();

}


problems comes when I am checking "user" variable by putting break point. it shows NULL. I don't understand this problem because as I am validating user in Page_Init() method and accessing logged in user by calling Membership.GetUser() method. According to me it should return "Guest"
plz Please help me out. Its urgent
Posted
Updated 2-Dec-10 20:29pm
v2

1 solution

In Page_Init you are creating a local scoped variable user of type MembershipUser. That object will be lost when Page_Init completes and will not be visible to other methods. You will need to store the user object that you have created in Page_Init, and then you will simply need to use that stored object instead of trying to create a new one in Page_Load.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900