Single page to determine if the browser accepts Cookies

Source: Internet
Author: User
Tags iis

In ASP applications, the session object is often used to hold the user's temporary private data, while the ASP's session object relies on the browser's cookie, and if the user accidentally turns off the cookie option for security reasons, the ASP will not recognize the user correctly, and the most Eventually causes the session object to not be used properly.
&NBSP
To correctly execute a later program, it is necessary to identify whether the client is accepting cookies, but the browser does not provide a way to identify whether the cookie is closed, so we need to do our own testing.
&NBSP
So many developers are using their own methods to test the cookie state of the browser, the most common method is to send a cookie in a page, and then test the existence of the cookie on another page. Since then, we need two ASP requests.
 
I'm here to introduce a way to test the state of a browser in conjunction with server script and client script.
 
When Netbox first initializes an ASP program, it assigns a new session object and sends a cookie to the client with a Application.applicationid name, if the browser accepts a cookie , the next time the Cookie,netbox server receives this Cookie, it will use its specified session object as the session object for this ASP request to ensure that the session object is unique and persistent for the specific user.
 
From this we know that we can determine whether or not the browser has accepted a Cookie with the name Application.applicationid to decide whether to continue with the following program. The browser's cookie object is used to determine if a cookie is contained in the explorer. The following code is the test browser has accepted the Netbox session:

<body>
<script language= "JavaScript" >
if (Document.cookie.search ("<%=application.applicationid%>=") = = 1) document.write ("not");
</script>allow.
</body>
The premise of this code is to know the name of the Cookie that Netbox sent out. If you want to use this code in IIS, it is more difficult because the name of the cookie that IIS sends out after each startup is different, so for testing, you can send a cookie and then test it:

<%response.cookie ("cookiecheck") = "on"%>
<body>
<script language= "JavaScript" >
if (Document.cookie.search ("cookiecheck=") = = 1) document.write ("not");
</script>allow.
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.