Checking cookies in asp.net

I want to check if a user's cookie is enabled. Most solutions include: 1. creating a cookie 2. redirecting the user to a custom page or the same page. 3. Read the cookie.

I have a problem at the second step. Should I use a query string when executing response.redirect so that on the next trip I know that the cookie has already been set and that I should try to read it? What if the user hard-codes the URL (along with this query string) in the browser while accessing the website? Also, if I find that cookies are enabled and I have set a session variable to say that cookies are enabled in that browser, so don't check again in this session. This is normal? If a session is available, is that a good enough indicator that cookies are enabled?

I want to minimize these double trips to each page for cookie validation.

+2


source to share


4 answers


I would use javascript to make an asynchronous request and check if cookies were returned in this request.



+1


source


Never miss a request. You already hinted at this above, but what if some trick draws our url and decides they want to submit their own request?



If the user has cookie preferences, you can establish a session and check this. Always check the session.

0


source


instead of using this method, which involves multiple steps and pages, and additional latency for the end user, can't you just use the HttpBrowserCapabilities class? This class has a Cookies property:

HttpBrowserCapabilities.Cookies Property

Grz, Kris.

0


source


According to my knowledge, I know Two ways to check if browser allows / accepts cookies

  • Using "Request.Browser.Cookies"

  • Using Javascript / JQuery

Example:

 if (Request.Browser.Cookies)
 {
       Response.Write("Welcome To Hello World Cookies Accepted by the browser");
 }
 else
 {
                Response.Write("Good Bye To Hello World. Cookie diabled in your browser. Enable cookies and Try again... Cool..");

 }

      

0


source







All Articles