In asp applications, the Session object is often used to save the user's temporary private data. The Session object of asp relies on the browser's Cookie. If the user turns off the Cookie option for security reasons or inadvertently, asp will not be able to correctly Identify the user, eventually causing the Session object to not be used normally.
To correctly execute subsequent programs, we must first identify whether the client program accepts cookies. However, the browser does not provide a method to identify whether cookies are turned off, so we need to find a way to test it ourselves.
So many developers have used their own methods to test the cookie status of the browser. The most common method is to send a cookie in one page, and then test whether the cookie exists in another page. In this way, we need two asp requests.
What I introduce here is a method that combines server scripts and client scripts to test the browser status at once.
When NetBox initializes the asp program for the first time, it will allocate a new Session object and send a Cookie named Application.ApplicationID to the client. If the browser accepts the Cookie, it will send back this Cookie on the next visit. NetBox After the server receives this Cookie, it will select the specified Session object as the Session object for this ASP request to ensure the uniqueness and persistence of the Session object for the specific user.
From this we know that we can determine whether the following program can continue by determining whether the browser accepts the cookie named Application.ApplicationID. To determine whether the browser contains a cookie, you can use the browser's cookie object to complete it. The following code is to test whether the browser accepts the NetBox Session:
<html>
<body>
<Script language="javascript">
if(document.cookie.search("<%=Application.ApplicationID%>=") == -1)document.write("Not ");
</Script>Allow.
</body>
</html>
The premise of this code is to know the name of the cookie sent by NetBox. If you want to use this code in iis, it is more difficult because the name of the cookie sent by iis is different every time it is started. Therefore, for testing, you can send a cookie yourself and then test again:
<%Response.Cookie( "CookieCheck")="on"%>
<html>
<body>
<Script language="javascript">
if(document.cookie.search("CookieCheck=") == -1)document.write("Not ");
</Script>Allow.
</body>
</html>