- // on the master page or default page
- protected void Page_Load(object sender, EventArgs e)
- {
- // check for a cookie indicating cookie acceptance
- HttpCookie tokenCookie = Request.Cookies["AcceptsCookies"];
- if (tokenCookie == null)
- {
- tokenCookie.Expires = DateTime.Now.AddYears(1000);
- Response.Cookies.Add(tokenCookie);
- Response.Redirect("~/CheckCookies.aspx");
- }
- }
- // on the CheckCookies.aspx page
- protected void Page_Load(object sender, EventArgs e)
- {
- HttpCookie tokenCookie = Request.Cookies["AcceptsCookies"];
- if (tokenCookie != null)
- Response.Redirect("Default.aspx");
- }
Thursday, 8 July 2010
CHECK FOR COOKIE ACCEPTANCE
First time a user visits the site, there will be a double re-direct, but if they keep that cookie around (for 1000 years), that'll only ever happen the first time. Any user who does not accept cookies will get stuck on the CookieCheck.aspx page without a redirect. I use the first part of this on a master page, making the cookie check present for every page that inherits it
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment