经典 ASP:cookie 中的多个 ASPSESSIONID [英] Classic ASP: Multiple ASPSESSIONID in cookies

查看:39
本文介绍了经典 ASP:cookie 中的多个 ASPSESSIONID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经典的 asp 页面的问题,三天后我无法解决它.

I have a problem with a classic asp page and I just cannot solve it since 3 days.

页面正在使用会话 - 有时会发生在 Request.ServerVariables("HTTP_COOKIE") 中两次设置 ASPSESSIONID cookie.这会导致 ASP 页面在页面刷新时在两个会话之间跳转.

The page is working with Sessions - sometimes it happens that the ASPSESSIONID cookie is set twice in the Request.ServerVariables("HTTP_COOKIE"). This causes the ASP-Page to jump between the two Sessions when the page is refreshed.

我编写了一个测试页面,它输出当前的 SessionId、服务器软件和 HTTP_COOKIE 值.

I have written an Test page which outputs the current SessionId, the Server Software and the HTTP_COOKIE value.

样本输出:

会话 ID:308542840

Session ID: 308542840

会话超时:20 分钟

服务器软件:Microsoft-IIS/6.0

Server Software: Microsoft-IIS/6.0

HTTP_COOKIE:ASPSESSIONIDQCBATRAD=MBHHDGCBGGBJBMAEGLDAJLGF;ASPSESSIONIDQCCDTTCB=PGHPDGCBPLKALGGKIPOFIGDM

HTTP_COOKIE: ASPSESSIONIDQCBATRAD=MBHHDGCBGGBJBMAEGLDAJLGF; ASPSESSIONIDQCCDTTCB=PGHPDGCBPLKALGGKIPOFIGDM

为什么有两个 ASPSESSIONID?当我刷新页面时,它会随机输出两个会话 ID 之一.

Why are there two ASPSESSIONIDs? When I refresh the page then it randomly outputs one of the two Session IDs.

这是一个截屏视频,显示了 IE9 中的问题:http://prinz-alexander.at/asp_test.avi

Here is a screencast which shows the problem in IE9: http://prinz-alexander.at/asp_test.avi

这个错误经常出现在ie8和ie9中.

This error often occurs in ie8 and ie9.

只需执行以下操作即可重现问题:

Just do the following to recreate the Problem:

  1. 完全关闭 IE8 或 IE9
  2. 启动 IE8 或 IE9 并打开 http://www.pfiffikus.at/pfiffikus/tests/
  3. 页面加载后立即刷新页面多次

如果您重复此步骤,则 HTTP_COOKIE 会随机(并非总是如此)填充有两个不同的 ASPSESSIONID.

If you repeat this steps then randomly (not always) the HTTP_COOKIE is populated with two different ASPSESSIONIDs.

asp 测试文件只输出mentiod 值,源代码中没有发生任何其他事情.

The asp test file is only outputing the mentiod values, nothing else is happening in the source code.

这是asp测试文件的代码:

This is the code of the asp test file:

<% If trim(Session("test_val")) = "" Then
     Dim my_num
     Randomize
     number = Int((rnd*1000))+1
     Session("test_val") = number
   End If
%>

<b>Session ID:</b>
<% response.write(Session.SessionId) %><br /><br />

<b>Session("test_val"):</b>
<% response.write(Session("test_val")) %><br /><br />

<b>Session Timeout:</b>
<% response.write(Session.Timeout) %> minutes<br /><br />

<b>Server Software:</b>
<% response.write(Request.ServerVariables("SERVER_SOFTWARE")) %><br /> <br />

<b>HTTP_COOKIE:</b> <% response.write(Request.ServerVariables("HTTP_COOKIE")) %>

如何避免 cookie 中出现多个 ASPSESSIONId?

How can i avoid multiple ASPSESSIONIds in cookies?

感谢您的帮助!

推荐答案

我能够使用 Javascript 删除这些 cookie.

I was able to remove those cookies with Javascript.

只需将下一个脚本添加到登录页面的末尾即可.这将在用户登录网站之前删除所有ASPSESSIONIDXXXXXXX"cookie:

Just add next script to the end of login page. This will remove all "ASPSESSIONIDXXXXXXX" cookies before user will login to website:

<script type="text/javascript">
    //Clear any session cookies
    (function(){
        var cookiesArr = document.cookie.split("; ");
        for (var i = 0; i < cookiesArr.length; i++) {
            var cItem = cookiesArr[i].split("=");
            if (cItem.length > 0 && cItem[0].indexOf("ASPSESSIONID") == 0) {
                deleteCookie(cItem[0]);
            }
        }

        function deleteCookie(name) {
            var expDate = new Date();
            expDate.setTime(expDate.getTime() - 86400000); //-1 day
            var value = "; expires=" + expDate.toGMTString() + ";path=/";
            document.cookie = name + "=" + value;
        }
    })();
</script>

这篇关于经典 ASP:cookie 中的多个 ASPSESSIONID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆