通过删除 cookie 的注销功能
Logout feauture by deleting cookies
我想通过在客户端删除 cookie 来创建注销功能。但是不知道怎么做
到目前为止,此代码无法正常工作。
任何帮助将不胜感激
<script>
function clearCookie(name, domain, path) {
var name = "yoursite.com"
var domain = ".yoursite.com";
var path = "/";
document.cookie = name + "=; expires=" + +new Date + "; domain=" + domain + "; path=" + path;
};
这是一篇来自 Coder Rocket Fuel 的文章
How to Create, Read, Update, & Delete Cookies in JavaScript
这是我的一些 C#...应该很容易翻译。
再次...您将过期设置为过去。
protected void CreateCookie(string location)
{
HttpCookie httpCookie = new HttpCookie("Location", location);
httpCookie.Expires = DateTime.Now.AddYears(10);
Response.Cookies.Add(httpCookie);
}
protected void DeleteCookie()
{
HttpCookie httpCookie = new HttpCookie("Location");
httpCookie.Expires = DateTime.Now.AddSeconds(-1);
Response.Cookies.Add(httpCookie);
}
我想通过在客户端删除 cookie 来创建注销功能。但是不知道怎么做
到目前为止,此代码无法正常工作。 任何帮助将不胜感激
<script>
function clearCookie(name, domain, path) {
var name = "yoursite.com"
var domain = ".yoursite.com";
var path = "/";
document.cookie = name + "=; expires=" + +new Date + "; domain=" + domain + "; path=" + path;
};
这是一篇来自 Coder Rocket Fuel 的文章
How to Create, Read, Update, & Delete Cookies in JavaScript
这是我的一些 C#...应该很容易翻译。 再次...您将过期设置为过去。
protected void CreateCookie(string location)
{
HttpCookie httpCookie = new HttpCookie("Location", location);
httpCookie.Expires = DateTime.Now.AddYears(10);
Response.Cookies.Add(httpCookie);
}
protected void DeleteCookie()
{
HttpCookie httpCookie = new HttpCookie("Location");
httpCookie.Expires = DateTime.Now.AddSeconds(-1);
Response.Cookies.Add(httpCookie);
}