1

嘿伙计们,

4

3 回答 3

2

如果您使用表单身份验证,只需将true其作为第二个参数传递给RedirectFromLoginPage

否则,想法本质上是相同的:您需要创建一个所谓的“持久 cookie ”,这意味着您必须指定正确的 cookie 到期日期。

于 2010-01-20T10:05:36.637 回答
1
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["myCookie"] != null)
                {
                    HttpCookie cookie = Request.Cookies.Get("myCookie");
                    txtUserName.Text = cookie.Values["username"];
                    txtPassword.Attributes.Add("value", cookie.Values["password"]);



                }
            }

        }
 protected void btnLogin_Click(object sender, EventArgs e)
        {
 bool IsRemember = chkRememberMe.Checked;
                    if (IsRemember)
                    {
                        myCookie.Values.Add("username", txtUserName.Text);
                        myCookie.Values.Add("password", txtPassword.Text);
                        myCookie.Expires = DateTime.Now.AddDays(15);
                    }
                    else
                    {
                        myCookie.Values.Add("username", string.Empty);
                        myCookie.Values.Add("password", string.Empty);
                        myCookie.Expires = DateTime.Now.AddMinutes(5);
                    }
 Response.Cookies.Add(myCookie);
}
于 2011-11-01T10:23:14.950 回答
0

看看这里:如何:创建 ASP.NET 登录页面

<asp:Login ID="Login1" 
           runat="server" 
           DestinationPageUrl="~/MembersHome.aspx">
</asp:Login>
于 2010-01-20T10:08:00.797 回答