第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何手動創(chuàng)建身份驗證cookie而不是默認(rèn)方法?

如何手動創(chuàng)建身份驗證cookie而不是默認(rèn)方法?

米脂 2019-10-08 09:59:30
使用FormsAuthentication我們編寫如下代碼: if (IsValidUser()) {      FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);      FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie);  }如何手動創(chuàng)建身份驗證cookie而不是編寫FormsAuthentication.SetAuthCookie(userName, createPersistentCookie)?如何將登錄頁面中的重定向URL存儲在字符串變量中而不是編寫FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie)?
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗 獲得超9個贊

回答有關(guān)為此帖子 投下反對票的最新信息,創(chuàng)建具有用戶信息的cookie的方法如下,


登錄頁面頁面加載時的Cookie驗證,


if (HttpContext.Current.User.Identity.IsAuthenticated)

經(jīng)過身份驗證的用戶登錄期間創(chuàng)建Cookie,


 FormsAuthentication.SetAuthCookie(txtUserName.Text.Trim(), true);

 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(

    1,

    txtUserName.Text.Trim(), 

    DateTime.Now,

   (chkRemember.Checked) ? DateTime.Now.AddHours(6) : DateTime.Now.AddHours(2),// Specify timelimit as required

   true,

   string.Empty,                                                

   FormsAuthentication.FormsCookiePath);  

string encryptedTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

cookie.Expires = (chkRemember.Checked) ? DateTime.Now.AddHours(6) : DateTime.Now.AddHours(2);

cookie.HttpOnly = true;

Response.Cookies.Add(cookie);

以下是投反對票的答案 -在Cookie中添加加密密碼的原因。


另一種創(chuàng)建cookie的方式,


HttpCookie toolCookie = new HttpCookie("xyz");

toolCookie["UserName"] = userName;

toolCookie["Password"] = StringCipher.Encrypt(password, "#!");

toolCookie.Expires = DateTime.Now.AddMinutes(chkRemember.Checked ? 30 : -30);

Request.Cookies.Add(toolCookie);

參考


獲取現(xiàn)有的Cookie詳細(xì)信息


HttpCookie user = Request.Cookies["xyz"];

if(user != null)

 {

  string username = user["UserName"];

  string password = user["Password"] != null ? StringCipher.Decrypt(user["Password"], "#!")

 }

這里的數(shù)據(jù)安全性是一個靜態(tài)類。


加密和解密功能加密和解密


查看完整回答
反對 回復(fù) 2019-10-08
?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊

這是很大的幫助。我要做的唯一更改是從web.config獲取expiryDate超時時間。將DateTime.Now.AddMinutes(30)更改為DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes)

查看完整回答
反對 回復(fù) 2019-10-08
  • 3 回答
  • 0 關(guān)注
  • 564 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號