Bin and App_Code folders

Source: Internet
Author: User

If your Web application includes code to be shared among multiple pages, you can save the code in two special folders (Bin folder and App_Code folder) under the Web application root directory) in a folder.

Bin folder

The compiled assembly can be stored in the Bin folder, and other code (such as page Code) in any part of the Web application will automatically reference the folder. A typical example is the code compiled for the custom class. You can copy the compiled assembly to the Bin folder of the Web application so that this class can be used on all pages.

The Assembly in the Bin Folder does not need to be registered. ASP. NET can recognize the. dll file as long as it exists in the Bin folder. If you have changed. dll file, and write the new version to the Bin folder, ASP. NET will detect updates and use the new version for subsequent new page requests. dll file.

Bin Folder Security

Putting the compiled assembly into the Bin folder brings security risks. If the code is compiled and compiled by yourself, you can understand the functions of the Code. However, if the code is not compiled and compiled by yourself, you must treat the compiled code in the Bin folder like any executable code. Be cautious with compiled code before you complete code testing and are sure you have understood the code function.

Pay attention to the following security knowledge about whether to put compiled code into the Bin Folder:

The range of the Assembly in the Bin folder is the current application. Therefore, they cannot access resources outside the current Web application or call code outside the current Web application.

During runtime, the access level of the Assembly is determined by the trust level specified on the local computer.

If you use a designer such as Visual Studio, the context of code running in the Bin folder is different from that in the runtime. For example, the Code may run in full trust State.

App_Code folder

The source code can be stored in the App_Code folder, and the code will be automatically compiled at runtime. Any other code in the Web application can access the generated assembly. Therefore, the App_Code folder works in a similar way as the Bin folder. The difference is that you can store source code instead of compiled code. App_Code folder and its contents in ASP. NET Web applications allow you to create custom classes and other source-only files and use them in Web applications without having to compile them separately.

The App_Code folder can contain source code files written in the form of traditional class files (files with. vb,. cs, and other extensions. However, it can also contain files that are not explicitly displayed in a specific programming language. For example, the. wsdl (Web service discovery language) file and the XML schema (. xsd) file. ASP. NET can compile these files into an assembly.

The App_Code folder can contain any number of files and subfolders as needed. You can organize the source code in any way you think is convenient. ASP. NET will still compile all the code into a single assembly, and other code anywhere in the Web application can access the assembly.

Deduce the programming language of the App_Code folder

The App_Code folder is not explicitly marked as containing Files written in any programming language. On the contrary, ASP. NET deduce which compiler should be called for the App_Code folder Based on the files contained in the App_Code folder. If the App_Code folder contains the. vb file, ASP. NET uses the Visual Basic compiler. if it contains the. cs file, ASP. NET uses the C # compiler, and so on.

If the App_Code folder contains only files that do not explicitly indicate the programming language (for example. (wsdl file), ASP. NET will use the default compiler for Web applications. The default compiler is determined in the <compilation> element of the Web application or computer configuration file.

Use multiple programming languages in the App_Code folder

Because the source code in the App_Code folder must be 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 Visual Basic and C # at the same time.

However, you can configure a Web application to process the subfolders in the App_Code folder as independent compilation units. In this way, each folder can contain the source code written in different programming languages. Create a <codeSubDirectories> element in the <compilation> element of the Web. config file, and add a reference to the sub-folder to specify the configuration. The following example illustrates how to configure the subfolders VBCode and CSCode to compile them into different assemblies:

<Compilation debug = "false"> <codeSubDirectories> <add directoryName = "VBCode"/> <add directoryName = "CSCode"/> </codeSubDirectories> </compilation>

Note that references to VBCode and CSCode subfolders do not contain any information about the programming languages contained in subfolders. Just like the App_Code folder itself, ASP. NET will deduce the compiler to be used based on the files in the subfolders.

Security of the App_Code folder

The security issues of the Code in the App_Code folder are basically the same as those of the Code in the Bin folder-the Code must be compiled into an assembly and executed at runtime. Better than the Bin folder, you can read the source code of the file in the App_Code folder. However, if you do not fully understand the code, there are still security risks. Therefore, the attitude towards the source code in the App_Code folder must be as cautious as with the compiled code generated based on the same source code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.