C#注销问题,怎样使用cookie
来源:百度知道 编辑:UC知道 时间:2024/05/25 12:56:01
不好意思,我知道是在LinkButton的Click事件中让COOKIE过期,但是我是想问COOKIE是在哪个页面创建?我现在只是要能达到注销的效果就行,以前没用过COOKIE,所以请大家帮帮忙
Response.Cookies["userAdmin"].Expires = DateTime.Now.AddDays(-1);//让cookie过期自动消除
Response.Write("<script language=javascript>window.parent.opener=null;top.location.href='login.aspx';</script>");//跳转到登陆页
这段代码放到LinkButton单击事件中
用cookie完全可以解决,直接在linkbutton的onclick事件中将cookie置于过期,然后reponse.redirect你要去的页面就可以了。
下面给你说一下cookie的用法。
Cookie的用法也和ASP中差不多。比如我们建立一个名为aspcn,值为飞刀的cookie
HttpCookie cookie = new HttpCookie["aspcn"];
cookie.Value = "飞刀";
Response.AppendCookie(cookie);
我们取出Cookie值也很简单
HttpCookie cookie = Request.Cookies["aspcn"];
cookieValue = cookie.Value;
有时候我们想在一个Cookie中储存多个信息,那也没有问题。比如我们在名为aspcn的cookie下加多个信息
HttpCookie cookie = new HttpCookie("aspcn");
cookie.Values.Add("webmaster","飞刀");
cookie.Values.Add("writer","beige");
cookie.Values.A