Dipa Ahuja

Dipa Ahuja

  • NA
  • 3.1k
  • 713.7k

Session Data are being lost within few minutes

Oct 22 2009 11:11 AM

session data are lost dnt know by wich reason.. i have login form n by clicking on login button :
 
protected void Button1_Click(object sender, EventArgs e)
{
Session[
"uid"] = uname.Text.ToString();
Session[
"pwd"] = pwd.Text.ToString();
Server.Transfer(
"loginmid.aspx");
}

 

 
loginmid:
 
static
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection objConnection = new SqlConnection(strConnection);
SqlDataAdapter da;
DataTable dt = new DataTable();
DataSet ds = new DataSet();
string dq = "select * from login";
int i = 0;
int c = 0;
int chk;
protected void Page_Load(object sender, EventArgs e)
{
da =
new SqlDataAdapter(dq, strConnection);
ds =
new DataSet();
da.Fill(ds,
"login");

string uid = Session["uid"].ToString();
string pwd = Session["pwd"].ToString();


c = ds.Tables[
"login"].Rows.Count - 1;
i = 0;
while (i <= c)
{
if (ds.Tables["login"].Rows[i]["password"].ToString() == pwd && ds.Tables["login"].Rows[i]["uid"].ToString() == uid)
{
chk = 1;
}
i++;
}
if (chk == 1)
{
Label2.Text =
"Welcome " + uid + " You Have Successfully Login ";
Session[
"user"] = uid.ToString();
//Session[
"data"] = "no";
/*objConnection.Open();
SqlCommand comm = new SqlCommand("delete from tmp where uid=@uid", objConnection);
comm.Parameters.AddWithValue("@uid", user);
comm.ExecuteNonQuery();
objConnection.Close();*/

}
else
{
Label2.Text =
"Try Again";
}

}

home.aspx:
 
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
{
lblw.Text =
"Welcome Guest!";
hpcart.Visible =
false;
}
else
{
lblw.Text =
"Welcom " + Session["user"].ToString()+ "!!";
hpsin.Text =
"Sign Out |";
hpsin.NavigateUrl =
"signout.aspx";
hpcart.Visible =
true;
}
}

after login the label lblw: will be changed as welcom "username"..
the home.aspx dosnt have masterfile..
bt all other pages have ..
n even the masterfile.aspx.cs 's page_load contain same data about Session["user"]..
 
its working well.. bt after few minutes the lblw(which contain "welcom + userid" after login) changed as "Welcome Guest" which is state when user is not logged in..
 
y its happening?
 

Answers (5)