string strConnection = ConfigurationSettings.AppSettings["dns"];
        SqlConnection cn = new SqlConnection(strConnection);
        cn.Open();
        string strsql = "select name,pwd from user where name='" + name + "' or pwd='" + pwd + "'";
        SqlCommand cmd = new SqlCommand(strsql, cn);
        SqlDataReader rd = cmd.ExecuteReader();
        if (rd.Read())
        {
            if (rd.GetValue(0).ToString() == name)
            {
                if (rd.GetValue(1).ToString() == pwd)
                {
                    Session["LoginUser"] = rd.GetValue(0);
                    Response.Redirect("admincp.aspx");
                }
                else
                {
                    Response.Write("<script>alert('密码错误!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('用户名错误!')</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('用户不存在!')</script>");
        }我通过上面的一段代码实现了登录的登入功能,但现在的情况是,即便我是在登录后的页面进行了操作,处于活动状态,当我登录有一段时间后,就会自动退出登录,需要重新登录了,我想实现,就是我不点 退出 ,就一直不退出,只有点退出了,才会退出,其他即便关闭了IE,下次访问,还是不需要登录,请问这个该怎么做呢?谢谢

解决方案 »

  1.   

    关闭不需要登录,需要使用cookie如果如果登录完后,Session失效的时间长点就改web.config中的默认20分钟改长一些,如
    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data   source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="18000"/>
      

  2.   

    用Cookie保存,然后每次从cookie中读取数据.
      

  3.   

    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data  source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="18000"/>我使用了这个方法,但是没有效果COOKIE该怎么做呢?