为什么我用 cookie 保存了登陆信息。但是没有设置 cookie 保存时间 。默认应该是浏览器进程吧。   可是为什么还是会超时呢?我并没有关闭浏览器。麻烦大家看哈我的代码。我是想用户登陆成功后就保存到cookie  同时写入session ,session 超时的时候 会转到登陆页面 。在登陆页面 判断 cookie 是否为空。如果 不为空 就将值写入sessionlogin.aspx.cs
public partial class Login : BasePage
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = TextBox1.Text;
        name = name.Replace("'", "");
        name = name.Replace("=","");
        name = name.Replace("<","");
        name = name.Replace(">","");
        name = name.Replace("*","");
        string password = TextBox2.Text;
        password.Replace("'","");
        password.Replace("=", "");
        password.Replace("<", "");
        password.Replace(">", "");
        password.Replace("*", "");
        password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
        ZQ_ServicesLogin sl = new ZQ_ServicesLogin();
        DataTable dt = sl.Login(name, password);
        try
        {
            if (dt.Rows.Count > 0)
            {
                HttpCookie cookie = new HttpCookie("userinfo");    
                string myID;
                Session["UserID"] = dt.Rows[0]["ID"].ToString();
                myID=Session["UserID"].ToString();
                Session["GameID"] = dt.Rows[0]["GameID"].ToString();
                Session["PackName"] = dt.Rows[0]["PackName"].ToString();
                //Server.Transfer();  
                cookie.Values["name"] = name;              
                cookie.Values["pwd"]= password;
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.AppendCookie(cookie);
                sl = null;
                dt.Dispose();               
                
            }
            else
            { JavaScript.Alert(Page, "用户名或密码输入有误!"); }
        }
        catch(Exception ex)
        {
            Response.Write(ex);
            Response.End();
            JavaScript.Alert(Page, "登陆失败!"); }
        Response.Redirect("manage/index.aspx");
    }
}
BasePage.cs
public class BasePage: System.Web.UI.Page
{
public BasePage()
{
//
//TODO: 在此处添加构造函数逻辑
//
        if (HttpContext.Current.Response.Cookies["userinfo"]["name"] != null && HttpContext.Current.Response.Cookies["userinfo"]["pwd"]!=null)
        {
            string name = HttpContext.Current.Response.Cookies["userinfo"]["name"].ToString();
            string password = HttpContext.Current.Response.Cookies["userinfo"]["pwd"].ToString();
            ZQ_ServicesLogin sl = new ZQ_ServicesLogin();
            DataTable dt = sl.Login(name, password);
            if (dt.Rows.Count > 0)
            {
                string myID;
                Session["UserID"] = dt.Rows[0]["ID"].ToString();
                myID = Session["UserID"].ToString();
                Session["GameID"] = dt.Rows[0]["GameID"].ToString();
                Session["PackName"] = dt.Rows[0]["PackName"].ToString();
                sl = null;
                dt.Dispose();
                Response.Redirect("manage/index.aspx");
            }
        }
}
}