在ASP.NET中怎样用cookie保存用户名和密码到客户端,下次等自动显示用户名和密码(在MVC的情况下)
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;
}
{
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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询