Use resource files (2)

xiaoxiao2021-03-06  105

Use resource files

Create a resource

Use resources on the page

Use the accessory set

Access to controls

This section is summarized

Creating resource resource management is a feature of the .NET Framework class library, which can be used to extract localized elements from the source code and store them together with string keys as resources. When running, an instance of the ResourceManager class can be used to resource or localized version. Resources can be stored as a separate ("loose") file, or part of the assembly. ASP.NET Pages You can use resource files; in addition, compiled code hidden controls can be embedded or linked to resources in their program. You can use the ResourceWriter class to programmatically create a resource, or create a resource using the tool ResGen.exe. ResGen.exe can use a simple "key = value" format as an input, or use the .resx format XML file.

; [Strings] Greeting = Welcome! More = read more ...

ResourceWriter and Resgen.exe create a .resources file, which can be used separately or as part of the assembly. To include .resources files in the program, use the related compiler switch or Al.EXE tool. Only the localized resources are included, and the assembly that does not include the code is called an accessory set.

Use the example below to implement one .aspx page, which is localized for each request. The supported languages ​​are English, German and Japanese. The method of determining the language is to check the Content-Language field of the HTTP header in the global.asax file. The content of this field can be accessed via UserLanguages: