Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Delete Value from Cookie

Delete Value from Cookie

Scheduled Pinned Locked Moved ASP.NET
questiontutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdullah S Abdelhay
    wrote on last edited by
    #1

    Hello All, I want to delete value from cookie For Example: The Cookie name [myCooke] The Cookie Contains-------------------------------------------------------------------------------- myCookeLotID1=7amp;LotNo1=003462&LotName1=Lot 7&BuyPrice1=850&StockQuantity1=56 amp;amp;LotID2=5&LotNo2=003859&LotName2=Lot 3&BuyPrice2=154&StockQuantity2=2 localhost/1536149997862429993731246977484829981862* --------------------------------------------------------------------------------------------------- The question: How i can delete [LotName2=Lot 3] value from this cookie? please reply me quickly. Thank you Best Regards Abdullah S. Abdelhay

    J R 2 Replies Last reply
    0
    • A Abdullah S Abdelhay

      Hello All, I want to delete value from cookie For Example: The Cookie name [myCooke] The Cookie Contains-------------------------------------------------------------------------------- myCookeLotID1=7amp;LotNo1=003462&LotName1=Lot 7&BuyPrice1=850&StockQuantity1=56 amp;amp;LotID2=5&LotNo2=003859&LotName2=Lot 3&BuyPrice2=154&StockQuantity2=2 localhost/1536149997862429993731246977484829981862* --------------------------------------------------------------------------------------------------- The question: How i can delete [LotName2=Lot 3] value from this cookie? please reply me quickly. Thank you Best Regards Abdullah S. Abdelhay

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      I am going to assume that the cookie contents arn't exactly as you typed it...because it seems there are a few typos in it. The following should work:

      string cookie = "LotID1=7&LotNo1=003462&LotName1=Lot 7&BuyPrice1=850&StockQuantity1=56&LotID2=5&LotNo2=003859&LotName2=Lot 3&BuyPrice2=154&StockQuantity2=2";

      string[] values = cookie.Split('&');

      string[] newValues = (from cv in values
      let eqIdx = cv.IndexOf('=')
      let name = cv.Substring(0, eqIdx)
      let value = cv.Substring(eqIdx + 1)
      where name != "LotName2"
      select cv).ToArray();

      string newCookie = String.Join("&", newValues);

      R 1 Reply Last reply
      0
      • J Jon Rista

        I am going to assume that the cookie contents arn't exactly as you typed it...because it seems there are a few typos in it. The following should work:

        string cookie = "LotID1=7&LotNo1=003462&LotName1=Lot 7&BuyPrice1=850&StockQuantity1=56&LotID2=5&LotNo2=003859&LotName2=Lot 3&BuyPrice2=154&StockQuantity2=2";

        string[] values = cookie.Split('&');

        string[] newValues = (from cv in values
        let eqIdx = cv.IndexOf('=')
        let name = cv.Substring(0, eqIdx)
        let value = cv.Substring(eqIdx + 1)
        where name != "LotName2"
        select cv).ToArray();

        string newCookie = String.Join("&", newValues);

        R Offline
        R Offline
        rama charan
        wrote on last edited by
        #3

        in Fact you cannot delete value from a cookie but you should have to recreate the cookie with the new value as explained by the previous post.

        Rama Charan Prasad "Be happy and Keep smiling.Thats what u want be always..:)"

        1 Reply Last reply
        0
        • A Abdullah S Abdelhay

          Hello All, I want to delete value from cookie For Example: The Cookie name [myCooke] The Cookie Contains-------------------------------------------------------------------------------- myCookeLotID1=7amp;LotNo1=003462&LotName1=Lot 7&BuyPrice1=850&StockQuantity1=56 amp;amp;LotID2=5&LotNo2=003859&LotName2=Lot 3&BuyPrice2=154&StockQuantity2=2 localhost/1536149997862429993731246977484829981862* --------------------------------------------------------------------------------------------------- The question: How i can delete [LotName2=Lot 3] value from this cookie? please reply me quickly. Thank you Best Regards Abdullah S. Abdelhay

          R Offline
          R Offline
          Rajdev Ramasamy
          wrote on last edited by
          #4

          We cannot delete a cookie actually. But one thing we can do is like, we can set the expiry date of the cookie to prior date, so that the browser will remove the cookie when it access the cookie for the next time, since it is expired. Expiring the Cookie in Server Side:

          if (Request.Cookies["MyCookie"] != null)
          {
          HttpCookie myCookie = new HttpCookie("MyCookie");
          myCookie.Expires = DateTime.Now.AddDays(-1d);
          Response.Cookies.Add(myCookie);
          }

          <u>Expiring the Cookie in ClientSide Side:</u>

          <script type="text/javascript">
          <!--
          deleteCookie('MyCookie');
          // -->
          </script>

          Please reply on any doubts. Hope this will be usefull for you. Thanks, Rajdev KR

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups