JS脚本判断是否支持Cookie,C#读取设置Cookie
JAVASCRIPT判断IE是否开启COOKIE
<script type="text/javascript">
function CookieEnable()
{
var result=false;
if(navigator.cookiesEnabled)
return true;
document.cookie = "testcookie=yes;";
var cookieSet = document.cookie;
if (cookieSet.indexOf("testcookie=yes") > -1)
result=true;
document.cookie = "";
return result;
}
if(!CookieEnable())
{
alert("对不起,您的浏览器的Cookie功能被禁用,请开启");
}
</script>
function CookieEnable()
{
var result=false;
if(navigator.cookiesEnabled)
return true;
document.cookie = "testcookie=yes;";
var cookieSet = document.cookie;
if (cookieSet.indexOf("testcookie=yes") > -1)
result=true;
document.cookie = "";
return result;
}
if(!CookieEnable())
{
alert("对不起,您的浏览器的Cookie功能被禁用,请开启");
}
</script>
asp.net cookie
HttpCookie ck = Request.Cookies["cktest"];
if (ck == null)
{
ck = new HttpCookie("cktest");
ck.Value = "123";
ck.Expires = DateTime.Now.AddSeconds(20);//20秒的有效期
Response.Cookies.Add(ck);
Response.Write("new ck");
}
else
{
Response.Write(ck.Value.ToString());
}
//在一个Cookie中储存多个信息
/**//*
HttpCookie cookie = new HttpCookie("cktest");
cookie.Values.Add("v1","1");
cookie.Values.Add("v2","2");
cookie.Values.Add("v3","3");
Response.AppendCookie(cookie);
HttpCookie cookies = Request.Cookies["cktest"];
string value1 = cookies.Values["v1"];
string value2 = cookies.Values["v2"];
Response.Write(value1 + value2);
*/
本代码片段,后续会慢慢补充。