日期:2014-05-19  浏览次数:21168 次

C#怎么用COOKIE实现记住用户名?
在WEB页面用户登录之后就记住用户名,下次登录就不用填写用户名!

------解决方案--------------------
document.cookie= "key=aaaa;expires=datetime "
datetime:有效日期
read:document.cookie

------解决方案--------------------
var Cookie = {
setCookie : function(name, value)
{
document.cookie = name + "= " + escape(value) + "; ";
},

getCookie : function(name)
{
var arr = document.cookie.match(new RegExp( "(^| ) "+name+ "=([^;]*)(;|$) "));

if (arr != null)
{
return unescape(arr[2]);

}

return null;
},

deleteCookie : function(name)
{
document.cookie = name + "= ;expires=Fri, 02-Jan-1970 00:00:00 GMT ";
}
};

Cookie.setCookie( "name ", "value ");
Cookie.getCookie( "name ");
Cookie.deleteCookie( "name ");
------解决方案--------------------
if (登陆成功)
{
Response.Cookies[ "Login "][ "Name "] = "你的用户名 "
Response.Cookies[ "Login "].Expires = DateTime.Now.AddDays( "你想加的天数 ");
}