加密和解密cookie asp.net [英] encrypting and decrypting cookies asp.net
本文介绍了加密和解密cookie asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我想知道如何加密和解密cookies asp.net
i使用cookie实用程序我在哪里创建删除并读取我的cookie
这是我的代码
hi i wanna to know how can i encrypting and decrypting cookies asp.net
i use cookie utility where i create delete and read my cookie
this is my code
public static void CreateCookie(string CookieName, string[] keys, string[] values, bool Expired, HttpResponse res)
{
HttpCookie c = new HttpCookie(CookieName);
if (keys != null)
{
for (int x = 0; x < keys.Length; x++)
c.Values.Add(keys[x], values[x]);
if (!Expired)
c.Expires = DateTime.Now.AddDays(2);
}
else
c.Expires = DateTime.Now.AddDays(-2);
res.Cookies.Add(c);
}
public static string ReadFromCookie(string CookieName, string key, HttpRequest req)
{
try
{
return req.Cookies[CookieName][key].ToString();
}
catch
{
return null;
}
}
public static void RemoveCookie(string CookieName, HttpResponse res)
{
CreateCookie(CookieName, null, null, false, res);
}
在我的登录页面中我通过此代码创建cookie
in my login page i create cookie by this code
protected void btnLogin_Click(object sender, EventArgs e)
{
Member m = new Member();
if (m.Login(Txtuser.Text, Txtpass.Text))
{
utility.CreateCookie("login", new string[] { "user", "pass" }, new string[] { Txtuser.Text, Txtpass.Text }, ChkReM.Checked, Response);
Redirect(Txtuser.Text);
}
else
lblmsg.Text = "Username/password incorrect";
}
private void Redirect(string user)
{
if (user == "Admin")
Response.Redirect("Admin/Admin.aspx");
else
{
Response.Redirect("Users/UserInfo.aspx");
}
}
如何在此代码中加密和解密我的cookie
how can i encrypting and decrypting my cookies in this code
推荐答案
谷歌是你的朋友:好好经常拜访他。他可以比在这里发布问题更快地回答问题...
使用您的主题非常快速的搜索,因为搜索词给出了300,000次点击: Google [ ^ ]
In未来,请尽量自己做至少基础研究,不要浪费你的时间或我们的时间。
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave 300,000 hits: Google[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
这篇关于加密和解密cookie asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文