Domanda

Hi sorry this is my first post, I'm getting this error

"Error 1 Cannot implicitly convert type 'object' to 'UserData'. An explicit conversion exists (are you missing a cast?)"

I think its because im trying to change my session variable back into my object but I'm not sure how to do that, here is the code for changing the object into a session variable:

protected void Page_Load(object sender, EventArgs e)
{
    UserData temp = new UserData();
    temp = Session["userSesh"];
    if(temp.returnLoggedIn())
    {
        Label1.Text = "Welcome to the website " + temp.getUsername().ToString();
    }

the userSesh is was made with the following code:

            if (username == row["username"].ToString() && password ==      row["password"].ToString())
        {
            UserData user1 = new UserData();
            user1.setUsername(username);
            user1.setLoggedIn(true);
            Session["userSesh"] = user1;
            Response.Redirect("default2.aspx");

Thank you in advance

È stato utile?

Soluzione

Try converting session to UserData in this way too,

temp = Session["userSesh"] as UserData;

Altri suggerimenti

Cast it and set it

UserData temp=(UserData)Session["userSesh"];

Try converting session to UserData

temp = (UserData)Session["userSesh"];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top