Hii I am facing problem with session values .
I am having 2 sessions in my website.
1.LoginPage (1.Username)
2.MainPage to Transaction Page.
LoginPage Code
string Name = dr["Name"].ToString();
Session["UserName"] = Name;
Response.Redirect("Dashboard.aspx", false);
Master Page
if (!IsPostBack)
{
var a = "";
string Role_Id = "";
foreach (string Name in Session)
{
a = lblUser.Text = Session["UserName"].ToString();
a = lblUser1.Text = Session["UserName"].ToString();
}
if (a != "")
{
lblDate.Text = Convert.ToString(System.DateTime.Now.ToLongDateString());
lblTime.Text = Convert.ToString(System.DateTime.Now.ToShortTimeString());
hmcon.Open();
SqlCommand cmd = new SqlCommand("Select RoleId from MstRegisterUser where UserName='" + lblUser.Text + "'", hmcon);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Role_Id = dr["RoleId"].ToString();
}
dr.Close();
hmcon.Close();
if (Role_Id != "1")
{
liMasters.Visible = true;
liReports.Visible = true;
}
else
{
liMasters.Visible = false;
liReports.Visible = false;
}
}
else
{
Response.Redirect("LoginPage.aspx");
}
}
Main Page to Transaction Page
Session["Booking_ID"] = Booking_ID.Value;
Response.Redirect("Booking.aspx", false);
Reading value of Transaction Page.
foreach (string Booking_Id in Session)
{
SessionBooking_ID = hfBooking_ID.Value = Session["Booking_ID"].ToString();
string a = Session["UserName"].ToString();
}
Session.Remove("Booking_ID");
Getting error on Transaction page like object Reference.
I am unable to read session values on page.