我一直工作在一個腳本給用戶發送到登陸頁面,提供使用的HttpCookie他們尚未看到今天:布爾的HttpCookie重定向到着陸頁不能正常工作成功
bool userVisited = false;
HttpCookie cookie = Request.Cookies["Hoarding"];
if (cookie == null)
{
cookie = new HttpCookie("Hoarding");
cookie.Values.Add("userVisitedSplash", "true");
cookie.Expires = DateTime.Now.AddDays(1);
cookie.HttpOnly = true;
this.Page.Response.AppendCookie(cookie);
}
else
{
if (!Boolean.TryParse(cookie.Values["userVisitedSplash"], out userVisited))
{
userVisited = false;
}
else
{
Response.Redirect("/default-splash.aspx");
}
}
此代碼成功重定向,但一旦在着陸頁上按下輸入網站,它就會重新導向到飛濺。沒有考慮到它已經訪問過它。
這裏有什麼明顯的錯誤嗎?
您是否看到在瀏覽器中設置的cookie? – VisualBean
問題是如果有cookie並且TryParse成功,最後的'else'分支將被採用。 – user1429080