C# javascript 读写Cookie的方法
第一:写cookies
response.cookies["username"].value="guest";
response.cookies["username"].expires=datetime.now.adddays(1);
第二:添加cookies
httpcookie username_zhengshu_cookie = new httpcookie("uname");
username_zhengshu_cookie.value = "陈xx";
httpcookie userlession_zhengshur_cookie = new httpcookie("lcode");
userlession_zhengshur_cookie.value = "chen jian ping";
username_zhengshu_cookie.path = "/";
userlession_zhengshur_cookie.path = "/";
//限定有效期
userlession_zhengshur_cookie.expires = datetime.now.adddays(1);
username_zhengshu_cookie.expires = datetime.now.adddays(1);
response.cookies.add(userlession_zhengshur_cookie);
response.cookies.add(username_zhengshu_cookie);
//cookies添加
response.appendcookie(user_cookies);
//取值
response.write(request.cookies["uname"].value);
//javascript写读cookie
function set_cookie()
{
var setvalue="陈xx";
var exdate=new date();
exdate.setdate(exdate.getdate()+365);
document.cookie="userlession"+ "=" +setvalue+";expires="+exdate.togmtstring()+";path=/";
alert("已经写入cookie");
}
function get(){
var cookiestring=new string(document.cookie)
var cookieheader = "userlession="
var beginposition = cookiestring.indexof(cookieheader)
if(beginposition != -1)
{
alert(cookiestring.substring(cookieheader.length,cookiestring.indexof(";")));
}
}