在ASP.NET中怎样用cookie保存用户名和密码到客户端,下次等自动显示用户名和密码(在MVC的情况下)

2025-04-08 20:18:08
推荐回答(1个)
回答1:

public void SaveUserInfo()
{
Set("用户名","长沙极度信息技术有限公司");
Set("密码","最好加密保存,明文保存不安全");
}
public string GetUsername()
{return Get("用户名");}
public string GetPassword()
{return Get("密码");}

public static object Get(string key)
{
if (SessionOrCookies.ToLower() == "cookies")
{
return CookiesManager.Get(key);
}
HttpContext.Current.Session.Timeout = TimeOut;
return HttpContext.Current.Session[key];
}
public static void Set(string key, object value)
{
if (SessionOrCookies.ToLower() == "cookies")
{
CookiesManager.Set(key, value.ToString());
return;
}
HttpContext.Current.Session.Timeout = TimeOut;
HttpContext.Current.Session[key] = value;
}