我編碼爲我的基於mojoportal-iPhone優化的網站上的亞洲語言的學習模塊(工作正在進行中,英文資源沒有得到充分翻譯:http://ilearn.dandandin.it/kanatrainer.aspx)爲什麼在某些瀏覽器中,我的Session對象的值不正確?
這是一個簡單的「猜怎麼看這個」遊戲,與存儲在Session對象中的正確答案。
我不明白爲什麼,但是,expecially使用Safari瀏覽器,用戶將獲得別人的會話值
這是從代碼的摘錄(我刪除一些東西,翻譯變量)
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"]);
}
...
}
發生在視覺工作室,每個瀏覽器:
randomLetters是「你好」。用戶在文本框中寫入「hello」,並將「hello」與「hello」進行比較。標籤上寫着「正確!你好」。
在IIS中會發生什麼事,只是在基於WebKit的瀏覽器:
randomLetters是 「你好」。用戶在文本框中輸入「hello」,但「hello」與「goodbye」比較。標籤上寫着「錯誤!再見」。
我不明白如何會話[ 「randomLetters」]已經改變
公共VS私有代碼:
我使用Session [「名稱」] – 2011-05-09 09:49:50
嗯,我的意思是,怎麼是會話[「名稱」]爲存儲在服務器上? http://msdn.microsoft.com/en-us/library/ms178586.aspx – 2011-05-09 14:29:34
我認爲它存儲在服務器上,並通過保存在cookie上的標識符檢索,或者如果cookie支持它被禁用,則在url中傳遞值 – 2011-05-09 15:01:43