Monday, December 6, 2010

How: deleting cookies in ASP.

Cookies are used to store data on your computer by a Web browser.

When a browser connects to an account on a Web site and select a "remember me" check box, for example, a cookie is used to remember account information to the user. In contrast to the session timeout, and disconnect the user cookies, to stay until they expire and are deleted on the client computer. Difficulty: average

Instructions

Things you will need: Visual Studio .NET 2005 (2008)
  1. 1

    Create a cookie.

To remove a cookie, there must be. Everything you need create a cookie that is a call to the class, the name of the cookie and the data that you want to save.

EHowCookie HttpCookie = new HttpCookie ("Hello");
eHowCookie.Value = "say hello".
Add (eHowCookie).
  • 2

    Make sure that the cookie exists.

  • There is no point in a cookie that exist to ensure that the cookie delete to remove non-zero. In this example if the cookie "Hello" zero, the cookie does not exist then.

    HttpCookie cookie = request.cookies ["Hello"].
  • 3

    Delete the cookie.

  • Delete the cookie by you the expiration date in the past.

    Response.cookies ["Hello"] .expires = DateTime.Now.AddDays;
  • 4

    If you have set multiple cookies, you can delete all cookies from each one of you passes through.


  • String [] site cookies = Request.Cookies.AllKeys;
    Foreach (string cookie in site cookies)
    {
    Response.cookies [cookie] .expires = DateTime.Now.AddDays;
    }
  • 5

    Delete a cookie automatis

  • ch in définissfrüher a date of expiry on the client. This will delete the cookie from your computer after it has expired. The following removes a cookie five days from the date of the day.

    Response.cookies ["Hello"] .expires = DateTime.Now.AddDays (+ 5);

    No comments:

    Post a Comment