Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Session variables not saving
Old 01-10-2006, 11:32 AM Session variables not saving
Junior Talker

Posts: 1
Trades: 0
I have a login.aspx that user uses to login. It calls dologin.aspx which connects to the database, verifies the user information then sets the session variables. After setting the session variables it redirects to default.aspx which has 3 frames, header, menu and Report. When pipeline.aspx page loads in the report frame, all my session variables are gone. I try to Response.Write(Session["arType"]); and I get nothing. Below is the code for <B>DoLogin.aspx</B>
Code:
if (lobj_dataset.Tables[0].Rows.Count >0) {
     Session["UserID"]=lobj_dataset.Tables[0].Rows[0]["ID"];
     Session["Username"]=lobj_dataset.Tables[0].Rows[0]["Username"];
  Session["FullName"]=Convert.ToString(lobj_dataset.Tables[0].Rows[0]["FullName"]).Trim();
     Session["ARView"]=lobj_dataset.Tables[0].Rows[0]["ARView"];
     Session["Mapping"]=lobj_dataset.Tables[0].Rows[0]["Mapping"];
 Session["MenuUpdates"]=lobj_dataset.Tables[0].Rows[0]["MenuUpdates"];  Session["RootLevel"]=Convert.ToInt32(lobj_dataset.Tables[0].Rows[0]["RootLevel"]); 
 Session["AccountManager"]=lobj_dataset.Tables[0].Rows[0]["AccountManager"];
     Session["gridType"]=0;     Session["arType"]="%";
     Session["sortType"]="Priority, Company";     Session.Timeout=60;
     Response.Redirect("default.aspx", false); 
}
 else {
     Response.Redirect("login.aspx"); 
} 
lobj_connection.Close();
Any suggestions would be greatly appreciated, I've been stuck on this all day and need to move on as quick as possible.

Thanks,
Josh
Jster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-11-2006, 05:35 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
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
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to Session variables not saving
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52056 seconds with 12 queries