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. How to check cookies are enable or disable in borwser

How to check cookies are enable or disable in borwser

Scheduled Pinned Locked Moved ASP.NET
javascripttoolstutorial
10 Posts 3 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.
  • S Offline
    S Offline
    Samarjeet Singh india
    wrote on last edited by
    #1

    Hi all, If the client borwser is cookies disable then i want to show a message to client plz enable ur cookies....... for this i am writing this code but it is not working <script language="javascript" type="text/javascript"> function detect() { if(navigator.cookieEnabled) { alert('Your browser has cookies enabled.'); } else { alert('Your browser has cookies disabled.'); } } </script></head> <body onload="detect();"></body> Thanks a lot........

    A 1 Reply Last reply
    0
    • S Samarjeet Singh india

      Hi all, If the client borwser is cookies disable then i want to show a message to client plz enable ur cookies....... for this i am writing this code but it is not working <script language="javascript" type="text/javascript"> function detect() { if(navigator.cookieEnabled) { alert('Your browser has cookies enabled.'); } else { alert('Your browser has cookies disabled.'); } } </script></head> <body onload="detect();"></body> Thanks a lot........

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Just store a cookie and try to retrieve it using javascript. If proper value is retrieved, you will find cookie is enabled. ;)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      S 1 Reply Last reply
      0
      • A Abhishek Sur

        Just store a cookie and try to retrieve it using javascript. If proper value is retrieved, you will find cookie is enabled. ;)

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        S Offline
        S Offline
        Samarjeet Singh india
        wrote on last edited by
        #3

        Thnks for Replying ........ I am using IE and also block all cookies but allways answer is ........"cookies found" by fallowing code if (!IsPostBack) { Response.Cookies["test"].Value = "Samar"; Response.Cookies["test"].Expires = DateTime.Now.AddYears(30); if (Request.Cookies["test"] == null) Response .Write ("No cookie found"); else Response .Write ("cookies found"); } if I used gmail then message is comming that plz enable ur cookies ? while according previois code it means cookis is creaing ? then what is exat answer cookies is enable or disable ?

        A 1 Reply Last reply
        0
        • S Samarjeet Singh india

          Thnks for Replying ........ I am using IE and also block all cookies but allways answer is ........"cookies found" by fallowing code if (!IsPostBack) { Response.Cookies["test"].Value = "Samar"; Response.Cookies["test"].Expires = DateTime.Now.AddYears(30); if (Request.Cookies["test"] == null) Response .Write ("No cookie found"); else Response .Write ("cookies found"); } if I used gmail then message is comming that plz enable ur cookies ? while according previois code it means cookis is creaing ? then what is exat answer cookies is enable or disable ?

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          Did you try redirecting the page, and find cookies from another page ? Say in your page1 you place : Response.Cookies["test"] = "Samar"; In page2 you try to retrieve it using : if(Request.Cookies["test"] == null) Response.Write("No cookie found"); During the login process, Gmail actually redirects to more than one page before going to actual Gmail Console. So it is easier to them to understand if cookie is actually enabled or not. I think if you do like this in your login process, you can easily detect this. :)

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Windows7 API Code Pack
          Simplify Code Using NDepend
          Basics of Bing Search API using .NET

          S 1 Reply Last reply
          0
          • A Abhishek Sur

            Did you try redirecting the page, and find cookies from another page ? Say in your page1 you place : Response.Cookies["test"] = "Samar"; In page2 you try to retrieve it using : if(Request.Cookies["test"] == null) Response.Write("No cookie found"); During the login process, Gmail actually redirects to more than one page before going to actual Gmail Console. So it is easier to them to understand if cookie is actually enabled or not. I think if you do like this in your login process, you can easily detect this. :)

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Windows7 API Code Pack
            Simplify Code Using NDepend
            Basics of Bing Search API using .NET

            S Offline
            S Offline
            Samarjeet Singh india
            wrote on last edited by
            #5

            Yes ..........Dear I have done according to you in first page button clic event I M writng this ..... Response.Cookies["test"].Value = "Samar"; Response.Redirect("Default2.aspx"); and second page form load event if (Request.Cookies["test"] == null) Response.Write("No cookie found"); else Response.Write("cookie found"); I have disabled the cookie but it is still showing "Cookies found" Note-- I M using IE.

            A 1 Reply Last reply
            0
            • S Samarjeet Singh india

              Yes ..........Dear I have done according to you in first page button clic event I M writng this ..... Response.Cookies["test"].Value = "Samar"; Response.Redirect("Default2.aspx"); and second page form load event if (Request.Cookies["test"] == null) Response.Write("No cookie found"); else Response.Write("cookie found"); I have disabled the cookie but it is still showing "Cookies found" Note-- I M using IE.

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #6

              I think this means cookie is not disabled properly in your browser. If the cookie could be read, then browser didnt prevent it to store cookie properly. Also try in other browser and try publishing the application in IIS. :doh:

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Windows7 API Code Pack
              Simplify Code Using NDepend
              Basics of Bing Search API using .NET

              S 1 Reply Last reply
              0
              • A Abhishek Sur

                I think this means cookie is not disabled properly in your browser. If the cookie could be read, then browser didnt prevent it to store cookie properly. Also try in other browser and try publishing the application in IIS. :doh:

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Windows7 API Code Pack
                Simplify Code Using NDepend
                Basics of Bing Search API using .NET

                S Offline
                S Offline
                Samarjeet Singh india
                wrote on last edited by
                #7

                Yes it is Working in Mozilla but not in IE6 How can we check it IE6.........Thnks.......

                G 1 Reply Last reply
                0
                • S Samarjeet Singh india

                  Yes it is Working in Mozilla but not in IE6 How can we check it IE6.........Thnks.......

                  G Offline
                  G Offline
                  geeeeeeeetha
                  wrote on last edited by
                  #8

                  try this one Request.Browser.Cookies

                  S 1 Reply Last reply
                  0
                  • G geeeeeeeetha

                    try this one Request.Browser.Cookies

                    S Offline
                    S Offline
                    Samarjeet Singh india
                    wrote on last edited by
                    #9

                    I thing it is for ur borwser supports cookies or not but not for cookies enable or disable

                    A 1 Reply Last reply
                    0
                    • S Samarjeet Singh india

                      I thing it is for ur borwser supports cookies or not but not for cookies enable or disable

                      A Offline
                      A Offline
                      Abhishek Sur
                      wrote on last edited by
                      #10

                      I dont know.. But if you can still access the data with Cookies disabled, I think this would be the problem of security in the browser itself which allows the server to read cookies, even if it is disabled. I think it is always better not to rely on data in Cookies. I wonder how the client browser behaves and even clients can delete cookies any time. ;)

                      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                      My Latest Articles-->** Windows7 API Code Pack
                      Simplify Code Using NDepend
                      Basics of Bing Search API using .NET

                      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