Click here to Skip to main content
15,894,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
i m developing web application in asp.net with c#.I m Creating session in login page.
and displaying it to another page.it works fine,but when i upload it to server.
After 20 -30 seconds my session is automatically timed out. i m using web.config, in which session timeout is 20 minute.
can anyone solve my problem
thanks in advance.

My code is shown as below:
in login page button click event is as follows:

string usertype;
C#
protected void btnlogin_Click(object sender, EventArgs e)
    {
        cmd = new SqlCommand("Select UserName,Password,Type from tblLogin", con);
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            if (txtusername.Value == dr[0].ToString() && txtpass.Value == dr[1].ToString())
            {
                usertype = dr[2].ToString();
                flag = true;
                break;
            }
            else
            {
                flag = false;
            }
        }
        dr.Close();
        if (flag == true)
        {
            Session["utype"] = usertype;
            Response.Redirect("Default3.aspx");
        }
        else
        {
            //Response.Redirect("~/GPS/Default.aspx");
            //Response.Write("Username " + dr[0].ToString());
            //Response.Write("password " + dr[1].ToString());
            //Response.Write("Invalid LoginName Or Password");
            Response.Redirect("Default.aspx");
        }
    }


and i print this value in another page like this on page load event.

C#
string sessname;
    protected void Page_Load(object sender, EventArgs e)
    {
        sessname = Session["utype"].ToString();
        Response.Write(sessname);
    }
Posted
Updated 10-May-11 2:22am
v2

 
Share this answer
 
Comments
thatraja 11-Apr-11 10:49am    
Good link
m@dhu 12-Apr-11 0:23am    
Thanks raja.
Ashishmau 13-Apr-11 0:55am    
good link
m@dhu 13-Apr-11 1:07am    
Thanks.
NuttingCDEF 10-May-11 13:03pm    
Good link - my 5.
It's an another way to resolve your issue(with out increasing session time out).

How To Keep ASP.NET Session Alive[^]
 
Share this answer
 
Comments
NuttingCDEF 10-May-11 13:03pm    
Very helpful article - my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900