ASP.NETはログインユーザ名の具体的な実装を記憶する

1963 ワード

.aspxファイル
 
  








.aspx.csファイル
 
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtUser_Id.Focus();
            if (!Object.Equals(Request.Cookies["UserID"], null))
            {
                // Cookie ,
                HttpCookie readcookie = Request.Cookies["UserID"];
                this.txtUser_Id.Text = readcookie.Value;
            }
        }
    }
    private void CreateCookie()
    {
        // Cookie
        HttpCookie cookie = new HttpCookie("UserID");
        // Checkbox
        if (this.cbxRemeberUser.Checked)
        {
            // Cookie
            cookie.Value = this.txtUser_Id.Text;
        }
        // Cookie
        cookie.Expires = DateTime.MaxValue;
        // Cookie Cookie
        Response.AppendCookie(cookie);
}

    protected void btnInsert_Click(object sender, ImageClickEventArgs e)
    {

        if (object.Equals(Request.Cookies["UserID"], null))
        {
          // CreateCookie()
          CreateCookie();
        }
        else
        {
           CreateCookie();
        }

}