我有一个asp.net web应用程序,其中一个下拉框包含语言首选项(英语,法语)。当我选择法国我写的cookie如下 -asp.net cookies正在被覆盖
protected void ddChoice_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("pref");
cookie.Value = ddChoice.SelectedValue;
cookie.Expires = DateTime.Now.AddYears(1);
Response.SetCookie(cookie);
Thread.CurrentThread.CurrentCulture = new CultureInfo(ddChoice.SelectedValue);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(ddChoice.SelectedValue);
Server.Transfer(Request.Path);
}
和读取这个cookie在开始要求如下 -
protected void Application_BeginRequest(object sender, EventArgs e)
{
string lang = string.Empty;//default to the invariant culture
HttpCookie cookie = Request.Cookies["pref"];
if (cookie != null && cookie.Value != null && !string.IsNullOrEmpty(cookie.Value.Trim()))
lang = cookie.Value;
if (string.IsNullOrEmpty(lang))
lang = "en-US";
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
}
这个时候如果我检查浏览器cookie它被正确地设置为“FR- FR”。但在此之后,当我进入主页并刷新此页面时,Cookie将被设置为空白。
我不确定它在哪里被覆盖。任何帮助?
没有。测试用例是 - 1.转到主页 - 默认语言(英语),2.更改语言 - 它被更改,3.转到主页 - 正确选择语言(法语),4.击中F5 - 语言应该保持法语,但重设为英文。 – Codie 2012-04-03 06:50:54
为什么有'Server.Transfer(Request.Path)'? – IvanH 2012-04-03 08:54:02
将更新后的响应发送给客户端 – Codie 2012-04-03 09:14:41