Create a resx resource file in App_GlobalResources. For example:
In resx of different languages, the project should have the same name:
Chinese Resource item
English resource items
These names can be used right after they are finished,
Copy codeThe Code is as follows: <asp: Literal ID = "Literal1" runat = "server" Text = "<% $ Resources: lang, userinfo %>"/>
OrCopy codeThe Code is as follows: <% = Resources. lang. userinfo %>
Now you can change the browser's language preference to see the effect.
The next question is how to replace the language item through the program itself.
1. You can add <globalization culture = "en-US" uiCulture = "en-US"/> to web. config to change the default language used by the program.
2. Add the following code to the global application:
Copy codeThe Code is as follows: void Application_BeginRequest (Object sender, EventArgs e)
{
Try
{
If (Request. Cookies ["lang"]! = Null)
{
System. Threading. Thread. CurrentThread. CurrentCulture = System. Globalization. CultureInfo. CreateSpecificCulture (Request. Cookies ["lang"]. Value. ToString ());
System. Threading. Thread. CurrentThread. CurrentUICulture = new System. Globalization. CultureInfo (Request. Cookies ["lang"]. Value. ToString ());
}
}
Catch (Exception)
{}
}
You can change the cookie value to achieve real-time language switching, and easily implement multiple programming languages.
Download test:Global.rar (8.36 kb)