Session Seems to be lost when Button_Click event fired asp.net C#

ramarama

New Member
I came across a problem that I hope someone can help me solve. I am coding an ASP.NET website with C# and Entity Framework. I stored into a session a Login class I created. The class contains information such as the NetID, the Roles available to the user, and the role the user selects to login as. The problem I am encountering is that whenever I try to get the information that is stored in the session inside of a Button_Click event, it seems to not get the information. I do not know if this is allowed. However, I also put the Login variable that contains the user information as public variable for any function inside the partial class to access and I still have the same problem accessing the information inside a Button_Click event. When I get the Session information inside the Page_Load event, I am able to get the values that were placed inside that Session. The following is the code of my program.\[code\]public partial class Private_HomePagePortal : System.Web.UI.Page{Login SysUser = new Login();protected void Page_Load(object sender, EventArgs e){ string[] Roles; SysUser.Ticket = Request.QueryString["casticket"]; SysUser.GetNetID(); if (SysUser.Authenticate(SysUser.NetID)) { SysUser.GetRoles(SysUser.NetID); Roles = SysUser.Roles; CasOut.Text = "Welcome <b>" + SysUser.NetID + "</b>! You are now Logged in! " + "Please choose a role you would like to sign in as." + "<br>" + "<br>"; foreach (string item in Roles) { if (item == "Admin") { Admin.Visible = true; Admin.CssClass = "btn btn-danger"; AdminBreak.Text = "<br><br>"; } if (item == "SuperAdmin") { SuperAdmin.Visible = true; SuperAdmin.CssClass = "btn btn-danger"; SuperAdminBreak.Text = "<br><br>"; } if (item == "Member") { Member.Visible = true; Member.CssClass = "btn btn-danger"; MemberBreak.Text = "<br><br>"; } if (item == "Convener") { Convener.Visible = true; Convener.CssClass = "btn btn-danger"; ConvenerBreak.Text = "<br><br>"; } if (item == "ITAdmin") { ITAdmin.Visible = true; ITAdmin.CssClass = "btn btn-danger"; } } else CasOut.Text = "You are not in the IUCommittee System!!!! If you believe this is an error, contact the IT Administrator for assistance."; Session["Login"] = SysUser; Login User = (Login)Session["Login"]; //Used to test information is actually in the Session CasOut.Text = User.NetID;} protected void Admin_Click(object sender, EventArgs e){ Login User = (Login)Session["Login"]; User.SelectedRole = "Admin"; CasOut.Text = User.NetID + User.SelectedRole; Session["Login"] = User;}}\[/code\]I would greatly appreciate the help.Thank you,Antelmo
 
Back
Top