日期:2014-05-17  浏览次数:20528 次

C#端添加的cookies,前台JS代码能删掉吗?
C# code
HttpCookie hcUser = new HttpCookie("User");
            hcUser.Values.Add("username", Login1.UserName);
            hcUser.Values.Add("password", Login1.Password);
            hcUser.Expires = DateTime.Now.AddDays(30);
            Response.Cookies.Add(hcUser);



JScript code
function deleteCookie(name, path, domain) {
    if (getCookie(name)) document.cookie = name + '=' +
            ((path) ? ';path=' + path : '') +
            ((domain) ? ';domain=' + domain : '') +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


JScript code
function ExitClientClick(e) {
    deleteCookie("User");
}


我在JS的ExitClientClick里,想删掉这个cookies,不管用啊

------解决方案--------------------
改成这样是可以的

HttpCookie hcUser = new HttpCookie("User");
hcUser.Values.Add("username", "UserName");
hcUser.Values.Add("password", "Password");
hcUser.Expires = DateTime.Now.AddDays(30);
hcUser.HttpOnly = false;
hcUser.Path = "/";
Response.Cookies.Add(hcUser);

删除
function DelCookie(sName) {
document.cookie = sName + "=;expires=Thu, 26-Jul-2011 03:33:07 GMT; path=/;";
}