我有一个网站一直运行良好,直到我不得不删除一些不正确的资源文件。但是,这可能不是它不起作用的原因。基本上,像大多数多语言网站一样,用户可以通过单击标志来更改语言:
protected void imbEnglish_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("en-GB");
}
protected void imbFrench_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("fr-FR");
}
protected void imbGerman_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("de-DE");
}
protected void imbSpanish_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("es-ES");
}
protected void imbItalian_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("it-IT");
}
protected void imbPolish_Click(object sender, ImageClickEventArgs e)
{
SetCultureStoreCookie("fr-FR");
}
protected void SetCultureStoreCookie(string culture)
{
//Sets the cookie that is to be used by Global.asax
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = culture;
Response.Cookies.Add(cookie);
//Set the culture and reload the page for immediate effect.
//Future effects are handled by Global.asax
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
//Response.Redirect(Request.Path);
Server.Transfer(Request.Path);
}
正如评论中所说,文化的后续设置正在 Global.asax 中处理:
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["CultureInfo"];
if (cookie != null && cookie.Value != null)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
}
else
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
}
}
所有页面,包括母版页都有英文(默认)资源文件,我已经开始创建法文资源文件:
但是,当您单击法国国旗时,没有任何反应。我已经单步执行了代码,正在设置 cookie 并运行 Thread.CultureInfo 行。
关于在哪里检查的任何想法?
谢谢。