【正文】
I portions of an application while developers work on the behavior or code. The codebehind model is wellsuited to that environment. introduces an improved runtime for codebehind pages that simplifies the connections between the page and code. In this new codebehind model, the page is declared as a partial class, which enables both the page and code files to be piled into a single class at runtime. The page code refers to the codebehind file in the CodeFile attribute of the % Page % directive, specifying the class name in the Inherits attribute. Note that members of the code behind class must be either public or protected (they cannot be private). The advantage of the simplified codebehind model over previous versions is that you do not need to maintain separate declarations of server control variables in the codebehind class. Using partial classes (new in ) allows the server control IDs of the ASPX page to be accessed directly in the codebehind file. This greatly simplifies the maintenance of codebehind pages. Although you can place code inside each page within your site (using the inline or codebehind separation models described in the previous section), there are times when you will want to share code across several pages in your site. It would be inefficient and difficult to maintain this code by copying it to every page that needs it. Fortunately, provides several convenient ways to make code accessible to all pages in an application. Just as pages can be piled dynamically at runtime, so can arbitrary code files (for example .cs or .vb files). introduces the App_Code directory, which can contain standalone files that contain code to be shared across several pages in your application. Unlike , which required these files to be prepiled to the Bin directory, any code files in the App_Code directory will be dynamically piled at runtime and made available to the application. It is possible to place files of more than one language under the App_Code directory, provided they are partitioned in subdirectories (registered with a particular language in ). The example below demonstrates using the App_Code directory to contain a single class file called from the page. By default, the App_Code directory can only contain files of the same language. However, you may partition the App_Code directory into subdirectories (each containing files of the same language) in order to contain multiple languages under the App_Code directory. To do this, you need to register each subdirectory in the file for the application. configuration pilation codeSubDirectories add directoryName=Subdirectory/ /codeSubDirectories /pilation / /configuration Supported in version 1, the Bin directory is like the Code directory, except it can contain prepiled assemblies. This is useful when you need to use code that is possibly written by someone other than yourself, where you don39。t have access to the source code (VB or C file) but you have a piled DLL instead. Simply place the assembly in the Bin directory to make it available to your site. By default, all assemblies in the Bin directory are automatically loaded