記住登陸使用者名稱功能

來源:互聯網
上載者:User

標籤:style   blog   http   color   width   re   

                //進入頁面執行
         //讀取儲存的Cookie資訊 HttpCookie cookies = Request.Cookies["USER_COOKIE"]; if (cookies != null) { //如果Cookie不為空白,則將Cookie裡面的使用者名稱和密碼讀取出來賦值給前台的文字框。 this.Txt_username.Text = cookies["UserName"]; //這裡依然把記住密碼的選項給選中。 this.UseNameCheckBox.Checked = true; }
                   //登陸按鈕執行
                   //增加cookie HttpCookie cookie = new HttpCookie("USER_COOKIE"); if (this.UseNameCheckBox.Checked) { //所有的驗證資訊檢測之後,如果使用者選擇的記住密碼,則將使用者名稱和密碼寫入Cookie裡面儲存起來。 cookie.Values.Add("UserName", this.Txt_username.Text.Trim()); //這裡是設定Cookie的到期時間,這裡設定一個星期的時間,過了一個星期之後狀態保持自動清空。 cookie.Expires = System.DateTime.Now.AddDays(7.0); HttpContext.Current.Response.Cookies.Add(cookie); } else { if (cookie != null) { //如果使用者沒有選擇記住密碼,那麼立即將Cookie裡面的資訊情況,並且設定狀態保持立即到期。 Response.Cookies["USER_COOKIE"].Expires = DateTime.Now; } }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.