How to check whether or not the browser accepts cookies?


The following describes how to check whether or not the browser accepts cookies.

  1. //if the request Goes To server  
  2. if (!IsPostBack)  
  3. {  
  4.  // These Property Shows the capability of the Browser.If it returns true then Browser Support Otherwise It goes to else condition  
  5.    if (Request.Browser.Cookies)  
  6.    {  
  7.       //First time the QueryString Value will be null  
  8.       if (Request.QueryString["cookie"] == null)  
  9.       {  
  10.          //write the Cookies  
  11.          HttpCookie cookie = new HttpCookie("TestOfCookie""1");  
  12.          //add the introduction-of-cookies  
  13.          Response.Cookies.Add(cookie);  
  14.          //redirect the same page  
  15.          Response.Redirect("Default.aspx?cookie=1");  
  16.       }  
  17.       else  
  18.       {  
  19.           //On the Second Time QueryString Value is not Null  
  20.          //read the introduction-of-cookies  
  21.          HttpCookie cookie = Request.Cookies["TestOfCookie"];  
  22.          //check that whether the Cookies are enable or disable on client's machine  
  23.         if (cookie == null)  
  24.         {  
  25.           Response.Write("Your Browser Has Disabled The Cookie");  
  26.        }  
  27.    }  
  28. }  
  29.    else  
  30.    {  
  31.       Response.Write("Your Browser Doesn't Support Cookie");  
  32.    }  

No comments:

Post a Comment

Xamarin Android Project App

Xamarin Android Project App 1. Xamarin -- Make a CALCULATOR Android App   https://drive.google.com/open?id=0B8OPCXLrtKPmWC1FWWtFM2lraVk...