//*********************************新建一测试页面************aspx*********//
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ceshi.aspx.cs" Inherits="ceshi" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >
无标题页
//*********************************为了测试页面********初始cookie用cs文件*************//
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("PassportURl");
string eventUrl = http://www.5ixznr + Request.RawUrl.ToString();
Session["Url"] = eventUrl.ToString(); //记录当前的地址;
cookie.Values.Add("5ixznr", eventUrl.ToString()); //记录当前的地址;
HttpContext.Current.Response.Cookies.Remove("PassportURl"); //删除旧的同名Cookie
Response.AppendCookie(cookie);
}
//*********************************cookie.js函数*************//
// JScript 文件
function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = documents.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = documents.cookie.length;
var msg=document.getElementById("emailInfor");
msg.innerHTML="Wellcome "+documents.cookie.substring(unescape(documents.cookie.substring(offset, endstr)).indexOf("=")+13);
//return unescape(documents.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
documents.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
documents.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = documents.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (documents.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = documents.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
var msg=document.getElementById("emailInfor");
msg.innerHTML="取到为空";
//return null;
}
本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow