4 回答
TA贡献1735条经验 获得超5个赞
Response.Cookie("username").value="aa" 写入
username=Request.Cookies("username").value 读取
最好用SESSION比较方便
session("username")="aa" 写入
username=session("username") 读取
TA贡献1772条经验 获得超6个赞
C# :
方法1:
Response.Cookies["username"].Value="gjy";
Response.Cookies["username"].Expires=DateTime.Now.AddDays(1);
方法2:
System.Web.HttpCookie newcookie=new HttpCookie("username");
newcookie.Value="gjy";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
创建带有子键的cookies:
System.Web.HttpCookie newcookie=new HttpCookie("user");
newcookie.Values["username"]="gjy";
newcookie.Values["password"]="111";
newcookie.Expires=DateTime.Now.AddDays(1);
Response.AppendCookie(newcookie);
cookies的读取:
无子键读取:
if(Request.Cookies["username"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["username"].Value));
}
有子键读取:
if(Request.Cookies["user"]!=null)
{
Response.Write(Server.HtmlEncode(Request.Cookies["user"]["username"].Value));
}
TA贡献1860条经验 获得超9个赞
vb:
'COOKIE中设置
'帐号
Response.Cookies("userId") = userId
Response.Cookies("userId").Expires = 60 '保存时间,以天为单位
'密码
Response.Cookies("pw") = pw
Response.Cookies("pw").Expires = 60
'从COOKIE取得
Response.Cookies("userId")
Response.Cookies("pw")
如果Cookies中无值,取得为空字符串""
- 4 回答
- 0 关注
- 227 浏览
添加回答
举报