正しくないリソース ファイルをいくつか削除するまでは正常に機能していた Web サイトがあります。ただし、これが機能しない理由ではない場合があります。基本的に、ほとんどの多言語 Web サイトと同様に、ユーザーはフラグをクリックして言語を変更できます。
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 行が実行されます。
他に確認すべき場所についてのアイデアはありますか?
ありがとう。