asp.net Keep folders detailed _ Practical skills

Source: Internet
Author: User
1. Bin folder
The Bin folder contains the deployable assemblies that are required by the application for controls, components, or any other code that needs to be referenced. Any. dll files that exist in the directory are automatically linked to the application. If you leave unused or outdated files in this folder, you may be at risk of an ambiguity reference (ambiguous reference) exception. In other words, if two different assemblies define the same class (the same namespace and name), then the ASP.net runtime cannot determine which assembly should be used, thus throwing an exception. At development time, this is a common error when we rename a project or an assembly name. To avoid this error, be sure not to leave any unnecessary assemblies in the folder, or at least remove the following line of code from the <assemblies> section of the configuration file:
<add assembly= "*"/>
Of all the folders listed in Table 1.10, only the bin can be identified by the ASP.net 1.x application. This folder is mandatory.
2. App_Browser folder
The optional folder contains the. browser file. The. browser file describes the features and features of the browser (whether it is a mobile device browser or a desktop browser). Asp. NET installs a large number of. browser files in the Config\browser folder under the installation path that are shared by all applications. We just put the current application-specific browser files under the App_Browser folder. The contents of the. browser file are compiled On-the-fly to provide the latest browser information to the ASP.net runtime.
Let's talk a little more about having a custom. browser file can be helpful for scenarios. Imagine that your application uses a control that is not rendered effectively under a browser. When the host page is displayed in the specified browser, you can write a. browser file that forces asp.net to use a different adapter to build the control.
<browsers>
<browser id= "Browserid" >
<controlAdapters>
<adapter controltype= "Samples.customcontrol"
Adaptertype= "Samples.Adapters.CustomControlAdapter"/>
</controlAdapters>
</browser>
</browsers>
Assuming that Browserid matches one of the standard browsers identified by ASP.net, the. browser file shown above indicates that customcontroladapter rendering CustomControl is used under the specified browser.
3. App_Code folder
The App_Code folder is right in the Web application root directory and stores all class files that should be dynamically compiled as part of the application. These class files are automatically linked to the application without the need to add any explicit directives or declarations to the page to create dependencies. The class files placed in the App_Code folder can contain any recognizable asp.net components-custom controls, auxiliary classes, build providers, business classes, custom providers, HTTP handlers, and so on.
Note When you develop, changes to the App_Code folder cause the entire application to be recompiled. For large projects, this may not be popular and time-consuming. To this end, the code is encouraged to be modularized into different class libraries, organized in a logically related collection of classes. Most application-specific auxiliary classes should be placed in the App_Code folder.
All class files stored in the App_Code folder should use the same language. If the class file is written in two or more languages, you must create a subdirectory of the specific language to contain the classes written in each language. Once these class files are organized according to language, add a setting for each subdirectory in the Web.config file:
<compilation>
<codeSubDirectories>
<add directoryname= "Vbfolder"/>
</codeSubDirectories>
</compilation>
Importantly, subdirectories of a particular language should be registered in the Web.config file, otherwise all files under the App_Code folder will be compiled into a separate assembly, regardless of which folder they belong to. The configuration script described above describes a situation where all C # files are placed under the root directory of the App_Code folder, and several Visual Basic. NET class files into the Vbfolder directory. If the directory mentioned in the <codeSubDirectories> section does not exist, you will receive a compile error prompt.
The files in the App_Code root folder are compiled into App_code_xxx.dll assemblies, where xxx is a randomly generated sequence of characters. A file in a given subdirectory will be compiled into a dynamically created assembly named App_subcode_xxx_yyy.dll, where xxx indicates the name of the subdirectory, and YYY is a sequence of random characters. The,<codesubdirectories> section is valid only in the Web.config file in the application root directory.
You can create a strong-named assembly by placing a AssemblyInfo.cs file in the App_Code directory or any other subdirectory. Obviously, if the folder contains visual Basic. NET file, you will use the AssemblyInfo.vb file. An assembly configuration file can refer to a. snk file to hold a strong-named key.
Note To set a strong name for an assembly, you must first obtain a public/private key pair. You can obtain such a key pair by using the strong name (Strong name) tool (Sn.exe). The Strong Name tool is one of the SDK binary that we can find in the installation path of the. NET Framework. A key pair file usually has a. snk extension. You can save the file to an application folder and reference it in the AssemblyInfo.cs file, as follows:
[Assembly:assemblykeyfileattribute (@ "Yourkeypair.snk")]
Note that Visual Basic. NET searches for a key file in a directory that contains visual Studio solution, and the C # compiler looks for a key file in the directory that contains the binary. This property adjusts the path we use, or places the key file in the appropriate folder.
In any subsequent rebuild, the name of the Assembly will change. At the same time, when the old AppDomain request is over, delete the old assembly.
The App_Code folder does not contain only class files. In particular, it can contain and automatically process XSD files that represent the data schema. When you add an XSD file to the folder, the compiler resolves it into a typed dataset class and adds it to the application scope. In ASP.net 1.x, this work is done by Visual Studio. NET Wizard, which is done using a command-line utility (Xsd.exe).
Note When you use the Web.config file to register a component (for example, a custom server control or a custom HTTP handler), you typically require that you specify the assembly name that contains the code. If the component is defined in the App_Code folder, what name should be used to indicate the assembly? In this case, only the assembly information is ignored and the complete class name is specified. If no assembly is specified, the ASP.net runtime attempts to mount the class from any mounted assembly, including the dynamically created assembly for the App_Code folder.
4. App_Data folder
The App_Data folder should contain the local data store for the application. It typically contains data stores in the form of files, such as Microsoft Access or Microsoft SQL Server Express databases, XML files, text files, and any other files supported by the application. The folder contents are not processed by asp.net. This folder is the default location for the ASP.net provider to store its own data.
Note The default ASP.net account is granted full access to the folder. If you happen to change the ASP.net account, make sure that the new account is granted read/write access to the folder.

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.