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. ASP.NET
  4. Problem writing Cookie

Problem writing Cookie

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpquestion
9 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.
  • F Offline
    F Offline
    firestoper
    wrote on last edited by
    #1

    Hi Guru's I'm having problem on writing cookie, not on the code but I can't seem to find the actual cookie file that was created, I also tried to placed the cookie path to my project folder but I still can't seem to find the cookie that was created. Below is my code for creating cookie. Am I doing something wrong? Please advice Dim bcap As HttpBrowserCapabilities Dim bookmarkCookie As HttpCookie bcap = Request.Browser If Not bcap.Cookies = True Then wc_header.setError("Cannot bookmark page, Cookie is not enabled in this browser") Return False Else bookmarkCookie = New HttpCookie("pageBookmark") bookmarkCookie.Path = Server.MapPath("../") bookmarkCookie("pageID" & pID) = CType(pID, String) bookmarkCookie.Expires = Now.AddDays(1) Request.Cookies.Add(bookmarkCookie) Return True End If

    M 1 Reply Last reply
    0
    • F firestoper

      Hi Guru's I'm having problem on writing cookie, not on the code but I can't seem to find the actual cookie file that was created, I also tried to placed the cookie path to my project folder but I still can't seem to find the cookie that was created. Below is my code for creating cookie. Am I doing something wrong? Please advice Dim bcap As HttpBrowserCapabilities Dim bookmarkCookie As HttpCookie bcap = Request.Browser If Not bcap.Cookies = True Then wc_header.setError("Cannot bookmark page, Cookie is not enabled in this browser") Return False Else bookmarkCookie = New HttpCookie("pageBookmark") bookmarkCookie.Path = Server.MapPath("../") bookmarkCookie("pageID" & pID) = CType(pID, String) bookmarkCookie.Expires = Now.AddDays(1) Request.Cookies.Add(bookmarkCookie) Return True End If

      M Offline
      M Offline
      Mircea Grelus
      wrote on last edited by
      #2

      Cookies are saved in special folders on users computes and you cannot change this (well, you can if you change the registry settings on every machine for the cookies folder). The usual folder in which cookies are saved is _[WINdrive]_:\Documents and Settings\_[user name]_\Cookies

      Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

      F 1 Reply Last reply
      0
      • M Mircea Grelus

        Cookies are saved in special folders on users computes and you cannot change this (well, you can if you change the registry settings on every machine for the cookies folder). The usual folder in which cookies are saved is _[WINdrive]_:\Documents and Settings\_[user name]_\Cookies

        Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

        F Offline
        F Offline
        firestoper
        wrote on last edited by
        #3

        Thanks Mircea, I tried looking on the path you suggested but there seems to be no cookie folder, I also tried viewing hidden folders but still no luck, I don't know if its on the code although writing cookie is pretty straight forward. Dom

        M 1 Reply Last reply
        0
        • F firestoper

          Thanks Mircea, I tried looking on the path you suggested but there seems to be no cookie folder, I also tried viewing hidden folders but still no luck, I don't know if its on the code although writing cookie is pretty straight forward. Dom

          M Offline
          M Offline
          Mircea Grelus
          wrote on last edited by
          #4

          Yes, adding a cookie is straightforward. You just have to add it to the request. I noticed you are setting the Path property to your cookie. The path describes the url to which the cookie applies. The best thing to do is set the cookie from a page in the root folder and remove the Path property from your code.

          Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

          F 1 Reply Last reply
          0
          • M Mircea Grelus

            Yes, adding a cookie is straightforward. You just have to add it to the request. I noticed you are setting the Path property to your cookie. The path describes the url to which the cookie applies. The best thing to do is set the cookie from a page in the root folder and remove the Path property from your code.

            Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

            F Offline
            F Offline
            firestoper
            wrote on last edited by
            #5

            Hmm the path points to where the cookie will be created bookmarkCookie.Path = Server.MapPath("../") I replaced it to more a specific location but nada.. no cookie :( bookmarkCookie.Path = Server.MapPath("../_cookies") What do you mean by Set the cookie from a page in the root folder are you suggesting that I should place the page that writes cookie to the root? Please advice Dom

            M 1 Reply Last reply
            0
            • F firestoper

              Hmm the path points to where the cookie will be created bookmarkCookie.Path = Server.MapPath("../") I replaced it to more a specific location but nada.. no cookie :( bookmarkCookie.Path = Server.MapPath("../_cookies") What do you mean by Set the cookie from a page in the root folder are you suggesting that I should place the page that writes cookie to the root? Please advice Dom

              M Offline
              M Offline
              Mircea Grelus
              wrote on last edited by
              #6

              firestoper wrote:

              Hmm the path points to where the cookie will be created

              NO. The Path property indicates the path for which the cookie will be created. (path in your website structure)

              firestoper wrote:

              What do you mean by Set the cookie from a page in the root folder are you suggesting that I should place the page that writes cookie to the root?

              Either place the page in teh root or place the code that creates the cookie in a page from the root. And remove the Path property from your code.

              Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

              F 1 Reply Last reply
              0
              • M Mircea Grelus

                firestoper wrote:

                Hmm the path points to where the cookie will be created

                NO. The Path property indicates the path for which the cookie will be created. (path in your website structure)

                firestoper wrote:

                What do you mean by Set the cookie from a page in the root folder are you suggesting that I should place the page that writes cookie to the root?

                Either place the page in teh root or place the code that creates the cookie in a page from the root. And remove the Path property from your code.

                Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

                F Offline
                F Offline
                firestoper
                wrote on last edited by
                #7

                I just place the page where calls the writing of cookie file, also I removed the path location, but no cookies was generation on the root folder. Does the page needed to be on a live webserver to generation cookies? or does this run on local web instance? huhu.. Dom

                M 1 Reply Last reply
                0
                • F firestoper

                  I just place the page where calls the writing of cookie file, also I removed the path location, but no cookies was generation on the root folder. Does the page needed to be on a live webserver to generation cookies? or does this run on local web instance? huhu.. Dom

                  M Offline
                  M Offline
                  Mircea Grelus
                  wrote on last edited by
                  #8

                  firestoper wrote:

                  Does the page needed to be on a live webserver to generation cookies?

                  No. Cookies are generated on localhost as well.

                  firestoper wrote:

                  I just place the page where calls the writing of cookie file, also I removed the path location, but no cookies was generation on the root folder.

                  You just don't get it. Cookies are generated in SPECIAL FOLDERS according to the type of browser you use. Not in your website. The browser that you use decides where it stores them. Use this tool[^] to find the path where the cookie is generated if you use Internet Explorer as the browser.

                  Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

                  F 1 Reply Last reply
                  0
                  • M Mircea Grelus

                    firestoper wrote:

                    Does the page needed to be on a live webserver to generation cookies?

                    No. Cookies are generated on localhost as well.

                    firestoper wrote:

                    I just place the page where calls the writing of cookie file, also I removed the path location, but no cookies was generation on the root folder.

                    You just don't get it. Cookies are generated in SPECIAL FOLDERS according to the type of browser you use. Not in your website. The browser that you use decides where it stores them. Use this tool[^] to find the path where the cookie is generated if you use Internet Explorer as the browser.

                    Cheers, Mircea "Pay people peanuts and you get monkeys" - David Ogilvy

                    F Offline
                    F Offline
                    firestoper
                    wrote on last edited by
                    #9

                    Thank you for the help Mircea, I've been using firefox sorry for that, I downloaded the app that you've gave and run the cookie page on IE browser. I checked on my cookie folder (that was shown on special folder location app) but can't find the cookie I created. To make sure I run a cookie checking script to see if there was a cookie generated, but it skipped the condition which means no cookie was created, below is my code: pageBookmarkcookie = Request.Cookies("pageBookmark") If pageBookmarkcookie IsNot Nothing Then For x As Integer = 0 To pageBookmarkcookie.Values.Count - 1 Response.Write(pageBookmarkcookie.Values(x)) Next else response.write("no cookie found") End If regards Dom

                    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