本文介绍了从用户注销帐户后如何删除Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当用户从其帐户注销时,我想从应用程序中删除Cookie,
有可能吗?
如果是,请建议我该怎么做?




感谢adv.

Hello guys,

I want to delete cookies from my application when user signout from his account,
is it possible?
if yes please suggest me the way how can i do this?




thanks in adv.

推荐答案

window.onbeforeunload = function() {
   var cookies = document.cookie.split(";");
   for (var i = 0; i < cookies.length; i++)
      eraseCookie(cookies[i].split("=")[0]);
};

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


代码参考 [ ^ ]


Code Reference[^]


if (Request.Cookies["userId"] != null)
    {
        Response.Cookies["userId"].Expires = DateTime.Now.AddDays(-1);   
    }


但是使用
也很有意义


But it also makes sense to use

Session.Abandon();


此处找到它 [ ^ ]

请参阅:退出时删除Cookie [ ^ ]


Found it here[^]

Refer: Delete cookies on sign out[^]


这篇关于从用户注销帐户后如何删除Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 23:17