App_globalresources in Asp.net 2.0 can be used to solve the localization problem. The program automatically determines the localized Interface Based on the browser's language preferences.
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,
<Asp: literal id = "literal1" runat = "server" text = "<% $ resources: Lang, userinfo %>"/>
Or
<% = 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:
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.