ASP.NET Sample Application

The ASP.NET code demonstrated here was taken from the Resources and Localization Using the .NET Framework SDK tutorial, which describes the entire resource creation process in detail. The code shown here has been slightly modified to move the procedural portion — written in Visual C# — into a separate Default.cs file. This approach, which is taken by Visual Studio .NET, helps to isolate the procedural code from the presentation layer.

The sample for debugging also makes use of a Web.config file with a compilation section and a debug attribute. (The sample could have used a trace attribute instead, which operates in the same way). Here is the complete Web.config file:

<configuration>
  <system.web>
    <compilation debug="true"/>
    <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" />
  </system.web>
</configuration>

Note that this debug setting should be enabled only when you are debugging an application, because it significantly affects the performance of the application. You could also specify the debug attribute in the Machine.config file that is located in the .NET common language runtime directory. This setting will then affect all applications running on that computer.

The Visual C# source code defines a MyCodeBehind class as well as a ResourceManager named rm, both of which are referenced in the ASP.NET page. The code — located in Default.cs and greatly shortened here — shows how these types are created.

public class MyCodeBehind : Page {
   public ResourceManager rm;
   ...
   public void Page_Load(Object sender, EventArgs args) {
      ...
      rm = (ResourceManager) Application["RM"];
   }
}

The other major file in this small application is the Web page itself, named Default.aspx, which is also shown greatly abbreviated.

<%@Page Description="Localized Page" Inherits="MyCodeBehind" Src="default.cs" trace="false"%>
...
<%=rm.GetString("greeting") %>

Before debugging this application, it is first necessary to compile the .resources files, by using Resgen.exe in the corresponding Build.bat file, as shown here:

resgen resources\mytext.txt       resources\mytext.resources
resgen resources\mytext.de-DE.txt    resources\mytext.de-DE.resources
resgen resources\mytext.en-US.txt resources\mytext.en-US.resources
resgen resources\mytext.ja-JP.txt    resources\mytext.ja-JP.resources

Again, the Resources and Localization using the .NET Framework SDK tutorial covers this step in greater detail.

See Also

Debugging the ASP.NET SampleApplication | Appendix A: For Additional Information | Appendix B: Runtime Debugger (CorDbg.exe)