Page.UICulture — How do I retrieve the Two Letter UICulture Code?

廉价感情. 提交于 2019-12-10 20:57:18

问题


In ASP.NET webforms, when setting UICulture="en" in the @Page directive, a Response.Write(Page.UICulture) returns the string "English" instead of the two letter language code "en".

Is the the only way to return the two letter language name by using this?

CultureInfo.CurrentUICulture.TwoLetterISOLanguageName

Or is there a better / more elegant way?


回答1:


Honestly I don't know of any better way to do it.

You could create an extension method, but that might be overkill:

public static class Extensions
{
    public static string GetUICultureCode(this System.Web.UI.Page page)
    {
        return System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
    }
}

Then in your page you can access it with this.GetUICultureCode()



来源:https://stackoverflow.com/questions/1171973/page-uiculture-how-do-i-retrieve-the-two-letter-uiculture-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!