Shared code folder in asp.net website
If your web application includes code that you want to share among multiple pages, you can save the code in a file in two special folders (Bin folder and App_Code folder) in the root directory of the web application Clamped. When you create these folders and store specific types of files in them, ASP.NET handles those files in a special way.
Bin folder You can store compiled assemblies in the Bin folder, and other code (such as page code) anywhere in the Web application automatically references the folder. A typical example is your compiled code for a custom class. You can copy the compiled assembly into the Bin folder of your Web application so that all pages can use this class.
Assemblies in the Bin folder do not need to be registered. As long as the .dll file exists in the Bin folder, ASP.NET will recognize it. If you change the .dll file and write a new version of it to the Bin folder, ASP.NET will detect the update and use the new version of the .dll file for subsequent new page requests.
Bin Folder Security Placing compiled assemblies in the Bin folder poses a security risk. If you wrote and compiled the code yourself, you know what the code does. However, you must treat the compiled code in the Bin folder like any executable code. Be cautious about compiled code until you have tested it and are confident that you understand its functionality.
Please note the following security aspects related to whether or not to place compiled code in the Bin folder:
Assemblies in the Bin folder are scoped to the current application. Therefore, they cannot access resources outside the current Web application or call code outside the current Web application.
At run time, the access level of an assembly is determined by the trust level specified on the local computer. For more information, see ASP.NET Trust Levels and Policy Files.
If you are using a designer such as Visual Studio, the code in the Bin folder runs in a different context than when it is run. For example, the code might run with full trust.
App_Code folder You can store source code in the App_Code folder, which will be automatically compiled at run time. Any other code in the web application can access the resulting assembly. Therefore, the App_Code folder works much like the Bin folder, except that you can store source code in it instead of compiled code. The App_Code folder and its special place in ASP.NET web applications allows you to create custom classes and other source code-only files and use them in your web application without having to compile them separately.
The App_Code folder can contain source code files written in the form of traditional class files (that is, files with .vb, .cs, etc. extensions). However, it can also contain files that do not explicitly appear to be written in a specific programming language. Examples include .wsdl (Web Services Description Language) files and xml schema (.xsd) files. ASP.NET can compile these files into assemblies.
The App_Code folder can contain as many files and subfolders as you need. You can organize your source code any way you find convenient, and ASP.NET will still compile all code into a single assembly, and that assembly can be accessed by other code anywhere in the Web application.
Notice
User controls are not allowed in the App_Code folder. This includes single-file user controls as well as user controls that use the code-behind model. Placing the user control in the App_Code directory causes the user control code to be compiled out of the order required and is therefore not allowed. Note that there is no need to place the user controls in the App_Code folder; these controls are already available to pages anywhere in the application.
Infer the programming language of the App_Code folder
The App_Code folder is not explicitly marked as containing files written in either programming language. Instead, ASP.NET infers which compiler should be invoked for the App_Code folder based on the files it contains. If the App_Code folder contains .vb files, ASP.NET uses the Visual Basic compiler; if it contains .cs files, ASP.NET uses the C# compiler, and so on.
If the App_Code folder contains only files that do not explicitly indicate a programming language (such as .wsdl files), ASP.NET will use the web application's default compiler, which is found in the compilation element of the web application or computer configuration file Sure.
Using Multiple Programming Languages in the App_Code Folder Because the source code in the App_Code folder is compiled into a single assembly, all files in the App_Code folder must be written in the same programming language. For example, the App_Code folder cannot contain source code written in both Visual Basic and C#.
However, you can configure your web application to treat subfolders of the App_Code folder as separate compilable units. This way, each folder can contain source code written in a different programming language. You specify this configuration by creating a compilation element in the codeSubDirectories element of the Web.config file and then adding a reference to the subfolder. The following example illustrates how to configure subfolders named VBCode and CSCode to compile into different assemblies:
Copy code
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VBCode" />
<add directoryName="CSCode" />
</codeSubDirectories>
</compilation>References to the VBCode and CSCode subfolders need not include any information about the programming languages contained in the subfolders. Just like with the App_Code folder itself, ASP.NET infers the compiler to use based on the files in the subfolder.
App_Code folder security
The security issues with code in the App_Code folder are basically the same as the security issues with code in the Bin folder - the code is compiled into an assembly at run time. What's better than the Bin folder is that you can read the source code of the files in the App_Code folder. However, there are still security risks if you don't fully understand the code. Therefore, the source code in the App_Code folder must be treated with the same caution as compiled code generated from the same source code.
Excerpted from: http://msdn2.microsoft.com/zh-cn/library/t990ks23(VS.80).aspx
-