语言文化在ASP登录时恢复为默认值

时间:2014-10-27 15:28:05

标签: c# asp.net culture

使用CurrentCulture显示威尔士语/英语内容时遇到问题。请考虑以下事项:

我有一个MasterPage,其中包含2个页眉和2个页脚,分别为英语/威尔士语。我在Page_Load的{​​{1}}事件中包含此代码块:

MasterPage

我在名为 if (Thread.CurrentThread.CurrentCulture.ToString() == "cy-GB") { Footer1.Visible = false; Footer2.Visible = true; Header1.Visible = false; Header2.Visible = true; } if (Thread.CurrentThread.CurrentCulture.ToString() == "en-GB") { Footer2.Visible = false; Footer1.Visible = true; Header1.Visible = true; Header2.Visible = false; } 的标题的威尔士语和英语版本中有一个链接,它会触发文化的变化,如下所示:

header.cy-GB.ascx.cs

languagelink

header.en-GB.ascx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            string currentPage = Request.Url.AbsoluteUri.ToString();

            //The culture is welsh, set the language change link to English
            if (Thread.CurrentThread.CurrentCulture.ToString() == "cy-GB")
            {
                Uri uri = new Uri(currentPage);
                languagelink.HRef = String.Format(uri.GetLeftPart(UriPartial.Path) + "?lang=en-GB");
            }
        }

这一切都运行得很好,但是在我的“主页”页面上你必须使用ASP会员登录,我注意到如果我点击 protected void Page_Load(object sender, EventArgs e) { string currentPage = Request.Url.AbsoluteUri.ToString(); //The culture is English, set the language change link to Welsh if (Thread.CurrentThread.CurrentCulture.ToString() == "en-GB") { Uri uri = new Uri(currentPage); languagelink.HRef = String.Format(uri.GetLeftPart(UriPartial.Path) + "?lang=cy-GB"); } } 按钮切换到威尔士语,然后登录,一旦我进入下一页,文化又回到了“en-GB”。我的印象是,一旦文化被改变,它将保持在那种状态,直到申请说不然。在登录页面中,用户被重定向到languagelink,执行以下操作:

Default.aspx.cs

Default.aspx

如果我在单步执行public partial class Secure_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string debug = Thread.CurrentThread.CurrentCulture.ToString(); RoleRedirect(); } public void RoleRedirect() { if (MembershipUtil.IsCurrentUserAdmin()) { if (Thread.CurrentThread.CurrentCulture.ToString() == "en-GB") { Response.Redirect("~/Secure/Admin/Default.aspx"); } if (Thread.CurrentThread.CurrentCulture.ToString() == "cy-GB") { Response.Redirect("~/Secure/Admin/Default.aspx?lang=cy-GB"); } } else { if (Thread.CurrentThread.CurrentCulture.ToString() == "en-GB") { Response.Redirect("~/Secure/CustomerSummary.aspx"); } if (Thread.CurrentThread.CurrentCulture.ToString() == "cy-GB") { Response.Redirect("~/Secure/CustomerSummary.aspx?lang=cy-GB"); } } } } 和标题页面时将语言设置为威尔士语,那么文化就会像我期望的那样受到欢迎。然而,当我登录并再次步骤时,当断点到达MasterPage上的string debug行时,文化又回到Default.aspx.cs,即使它已设置为威尔士语?任何人都可以建议这里可能会发生什么?

修改

我可能应该提到我已经创建了一个BasePage类,其中所有上述页面(Login,Default,CustomerSummary)都继承自:

en-GB

0 个答案:

没有答案