The following describes how to check whether or not the browser accepts cookies.
- //if the request Goes To server
- if (!IsPostBack)
- {
- // These Property Shows the capability of the Browser.If it returns true then Browser Support Otherwise It goes to else condition
- if (Request.Browser.Cookies)
- {
- //First time the QueryString Value will be null
- if (Request.QueryString["cookie"] == null)
- {
- //write the Cookies
- HttpCookie cookie = new HttpCookie("TestOfCookie", "1");
- //add the introduction-of-cookies
- Response.Cookies.Add(cookie);
- //redirect the same page
- Response.Redirect("Default.aspx?cookie=1");
- }
- else
- {
- //On the Second Time QueryString Value is not Null
- //read the introduction-of-cookies
- HttpCookie cookie = Request.Cookies["TestOfCookie"];
- //check that whether the Cookies are enable or disable on client's machine
- if (cookie == null)
- {
- Response.Write("Your Browser Has Disabled The Cookie");
- }
- }
- }
- else
- {
- Response.Write("Your Browser Doesn't Support Cookie");
- }
- }
No comments:
Post a Comment