gpt4 book ai didi

c# - 为什么在某些浏览器中我的 Session 对象得到了错误的值?

转载 作者:太空宇宙 更新时间:2023-11-03 16:46:09 24 4
gpt4 key购买 nike

我正在为我的基于 mojoportal 的 iphone 优化网站编写亚洲语言学习模块(正在进行中,英语资源未完全翻译:http://ilearn.dandandin.it/kanatrainer.aspx)

这是一个简单的“猜猜这个”游戏,正确答案存储在 Session 对象中。

我不明白为什么,但是,特别是使用 Safari,用户会得到别人的 Session 值

这是代码的摘录(我删除了一些东西,翻译了变量)

    protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)
{
...
generateRandom();
}
}

protected void generateRandom()
{
int i, j = 0, livello = 5, chance = 0;
System.Random acaso = new Random();
...
while (j <= 0)
{
j = acaso.Next((Convert.ToInt32(TextBoxlunghezza.Text) + 1));
}
...
for (int k = 0; k < j; k++)
{
i = acaso.Next(livello);
Session["randomLetters"] += (globals.asianCharacters[i]);
...
}
...
}


protected void AnswerButton_Click(object sender, EventArgs e)
{
string compare = Server.HtmlEncode(InputTextBox.Text.ToLower());
if (compare == "")
{
Label1.Text = ("You did not write anything");
return;
}
if (Session["randomLetters"].ToString() != compare)
{
Label1.Text = ("Wrong!" + Session["randomLetters"]);
}
else
{
Label1.Text = ("Right!" + Session["randomLetters"]);
}
...
}

在 visual studio 中,每个浏览器都发生了什么:

randomLetters 是“你好”。用户在文本框中写“你好”,“你好”与“你好”进行比较。标签上写着“对!你好”。

iis 中发生的情况,仅在基于 webkit 的浏览器中:

randomLetters 是“你好”。用户在文本框中写“你好”,但“你好”与“再见”相比较。标签上写着“错了!再见”。

我不明白 Session["randomLetters"] 是如何改变的

公共(public)代码与私有(private)代码: the code

最佳答案

您如何存储 session 状态?曲奇饼?数据库?依此类推...我在浏览器缓存页面和 cookie 的方式上遇到过很多问题(通常是 IE 8)。通常,更改浏览器中的相应设置可以解决问题。我不知道这对这里是否有帮助。为了使其更健壮,我必须找到一种方法在其中一个设置不正确时通知用户。

关于c# - 为什么在某些浏览器中我的 Session 对象得到了错误的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com