I can't see anything wrong with the code above, the problem could be somewhere else.
First of all, make sure you have session cookies enabled in your browser. Try making a new project with 2 pages and set a single session variable on one page and test it on the other:
Page 1, just one button. In the OnClick event:
Session["test"] = "Foo";
Response.Redirect("page2.aspx");
Page 2, just a label. In the OnLoad event:
Label1.Text = (string)Session["test"];
and see if Page 2 displays Foo. If it doesn't, you most likely have a problem with the way sessions are set up, and not the code.
p.s. You don't need 2 pages to do a login. Login.aspx can have 2 textboxes and a button, and the login code can be put in the buttons OnClick event.
Also, your code will be cleaner if you set up a new object to hold the user details and just set a single session variable to hold that object:
Code:
public struct TUser
{
public int UserID
public string Username;
public string FullName;
public string ARView;
// ...etc
}
Code:
TUser MyUser = new TUser()
MyUser.Username = "Foo";
MyUser.FullName = "Foo Bar";
MyUser.ID = "42";
Session["CurrentUser"] = MyUser;
Code:
Label1.Text = "Welcome to our site, " + ((TUser)Session["CurrentUser"]).FullName;
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|