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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. The problem during writing into an existing cookie, after re running my web application..............

The problem during writing into an existing cookie, after re running my web application..............

Scheduled Pinned Locked Moved Web Development
helpquestion
4 Posts 2 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.
  • V Offline
    V Offline
    Vishnu Narayan Mishra
    wrote on last edited by
    #1

    The problem during writing into an existing cookie, after re running my web application hi to all forums members can any one tell me what is error in mine code, It create every time a new cookie, but i have to write into existing cookie. When i close my web application and re running my web application and, adding values into cookies it creates new cookies... why I m unable to understand.... following is my code... protected void btnAddCokkie_Click(object sender, EventArgs e) { CreateAndAddCookiesValue(); } private void CreateAndAddCookiesValue() { //Response.Cookies.Remove("ShowHistoryCookie"); if (Request.Browser.Cookies == true) { // Check the cookie Mycookie exist or not if (Request.Cookies["ShowHistoryCookie"] == null) { // If does Mycookie does not exist then create the cookie HttpCookie aShowHistoryCookie = new HttpCookie("ShowHistoryCookie"); Response.Cookies.Add(aShowHistoryCookie); // set expires to the datetime maxvalue Response.Cookies["ShowHistoryCookie"].Expires = DateTime.Now.AddMonths(1); //Response.Cookies["ShowHistoryCookie"].Expires = DateTime.MaxValue; //DateTime.Now.AddMonths(1) Response.Cookies["ShowHistoryCookie"]["URL"] += txtUrlLink.Text; } //Append UrlLink into existing cookie else { string strCookie = Request.Cookies["ShowHistoryCookie"]["URL"].ToString(); string strCook = strCookie; strCookie += "|" + txtUrlLink.Text; char[] splitter = { '|' }; string[] arInfo = new string[10]; arInfo = strCook.Split(splitter); int count = arInfo.Length; int intResult=-1; bool flag = false; //count to Restrict cookie to Store 10 UrlLink if (count <10) { //check to ensure that no duplicacy in UrlLink of cookies foreach (string str in arInfo) { intResult = str.CompareTo(txtUrlLink.Text); if (intResult == 0) { flag = true; break; } } i

    C 1 Reply Last reply
    0
    • V Vishnu Narayan Mishra

      The problem during writing into an existing cookie, after re running my web application hi to all forums members can any one tell me what is error in mine code, It create every time a new cookie, but i have to write into existing cookie. When i close my web application and re running my web application and, adding values into cookies it creates new cookies... why I m unable to understand.... following is my code... protected void btnAddCokkie_Click(object sender, EventArgs e) { CreateAndAddCookiesValue(); } private void CreateAndAddCookiesValue() { //Response.Cookies.Remove("ShowHistoryCookie"); if (Request.Browser.Cookies == true) { // Check the cookie Mycookie exist or not if (Request.Cookies["ShowHistoryCookie"] == null) { // If does Mycookie does not exist then create the cookie HttpCookie aShowHistoryCookie = new HttpCookie("ShowHistoryCookie"); Response.Cookies.Add(aShowHistoryCookie); // set expires to the datetime maxvalue Response.Cookies["ShowHistoryCookie"].Expires = DateTime.Now.AddMonths(1); //Response.Cookies["ShowHistoryCookie"].Expires = DateTime.MaxValue; //DateTime.Now.AddMonths(1) Response.Cookies["ShowHistoryCookie"]["URL"] += txtUrlLink.Text; } //Append UrlLink into existing cookie else { string strCookie = Request.Cookies["ShowHistoryCookie"]["URL"].ToString(); string strCook = strCookie; strCookie += "|" + txtUrlLink.Text; char[] splitter = { '|' }; string[] arInfo = new string[10]; arInfo = strCook.Split(splitter); int count = arInfo.Length; int intResult=-1; bool flag = false; //count to Restrict cookie to Store 10 UrlLink if (count <10) { //check to ensure that no duplicacy in UrlLink of cookies foreach (string str in arInfo) { intResult = str.CompareTo(txtUrlLink.Text); if (intResult == 0) { flag = true; break; } } i

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Vishnu Narayan Mishra wrote:

      Cookies.Remove("ShowHistoryCookie");

      One sensible thing to do in situations like this, is to define "ShowHistoryCookie' as a const string, and use that variable everywhere, so you never have to track down a typo anywhere and can easily change the value if you want to.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      V 1 Reply Last reply
      0
      • C Christian Graus

        Vishnu Narayan Mishra wrote:

        Cookies.Remove("ShowHistoryCookie");

        One sensible thing to do in situations like this, is to define "ShowHistoryCookie' as a const string, and use that variable everywhere, so you never have to track down a typo anywhere and can easily change the value if you want to.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        V Offline
        V Offline
        Vishnu Narayan Mishra
        wrote on last edited by
        #3

        Hi could'nt understand your solution, my questions is so simple, can u try to straight answer my question..

        Vishnu Narayan Mishra Software Engineer

        C 1 Reply Last reply
        0
        • V Vishnu Narayan Mishra

          Hi could'nt understand your solution, my questions is so simple, can u try to straight answer my question..

          Vishnu Narayan Mishra Software Engineer

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I'm sorry, I was trying to point out why your code is nasty and hard to read. Your question involved a ton of code, which was hard to read, and no comments on what you see when you debug the code, so I didn't really take the time to try to decipher it.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          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