There are many reserved folders in an ASP. NET application
1. Bin folder
The bin folder contains the deployable assembly required by the application for controls, components, or any other code to be referenced. Any. DLL files in this directory are automatically linked to the application. If unnecessary or expired files are left in the folder, the "ambiguous reference" exception may occur. In other words, if two different assemblies define the same class (the same namespace and name), the ASP. NET Runtime Library cannot decide which assembly should be used, thus throwing an exception. This is a common error during development when we rename a project or assembly. To avoid this error, do not retain unnecessary assembly in this folder, or delete the following code lines from the <assemblies> section of the configuration file at least:
<Add Assembly = "*"/>
Only bin in all folders listed in table 1.10 can be recognized by ASP. NET 1. x applications. This folder is mandatory.
2. app_browser folder
This optional folder contains the. Browser file .. The Browser file describes the features and functions of browsers (whether mobile devices or desktop browsers. ASP. NET has installed a large number of. browser files in the config \ Browser folder under the installation path, which are shared by all applications. We just put the Browser file exclusive to the current application in the app_browser folder .. The content of the browser file is instantly and dynamically compiled to provide the latest browser information to the ASP. NET Runtime Library.
Let's briefly talk about scenarios where a custom. Browser file may be helpful. Imagine that the application uses a control that cannot be effectively rendered in a browser. When the host page is displayed in the specified browser, you can write a. Browser file to force ASP. NET to generate the control using a different adapter.
<Browsers>
<Browser id = "browserid">
<Controladapters>
<Adapter controltype = "samples. customcontrol"
Adaptertype = "samples. adapters. customcontroladapter"/>
</Controladapters>
</Browser>
</Browsers>
If browserid matches one of the standard browsers recognized by ASP. NET, The. Browser file shown above indicates that customcontroladapter is used to render customcontrol in the specified browser.
3. app_code folder
The app_code folder is located in the root directory of the Web application. It stores all class files that should be dynamically compiled as part of the application. These class files are automatically linked to the application without adding any explicit commands or declarations on the page to create dependencies. The class files placed in the app_code folder can contain any identifiable ASP. NET component-custom controls, helper classes, build providers, business classes, custom providers, and HTTP processing programs.
Note that during development, changes to the app_code folder will cause the entire application to be re-compiled. This may be undesirable and time-consuming for large projects. To this end, we encourage you to modularize the code into different class libraries and organize the code according to the logically related class sets. Most of the helper classes dedicated to applications should be placed in the app_code folder.
All class files stored in the app_code folder should use the same language. If a class file is written in two or more languages, you must create subdirectories in a specific language to contain classes written in each language. Once these class files are organized by language, you must add a setting for each subdirectory in the web. config file:
<Compilation>
<Codesubdirectories>
<Add directoryname = "vbfolder"/>
</Codesubdirectories>
</Compilation>
It is important that subdirectories in specific languages should be registered in the web. config file. Otherwise, all files in the app_code folder will be compiled into a separate assembly no matter which folder they belong. The preceding configuration script describes the situation where all C # files are stored in the root directory of the app_code folder, and several Visual Basic. Net files are moved to the vbfolder directory. If the directory mentioned in the <codesubdirectories> section does not exist, a compilation error is reported.
Files in the app_code root folder are compiled into the app_code_xxx.dll assembly, where XXX is a random character sequence. The file in a given subdirectory will be compiled into a dynamically created Assembly named app_subcode_xxx_yyy.dll. xxx indicates the subdirectory name, And YYY indicates a random character sequence. The <codesubdirectories> section is valid only when the web. config file in the application root directory is set.
Place an assemblyinfo. CS file in the app_code directory or any other sub-directories to create a strongly-named assembly. Obviously, if the folder contains the Visual Basic. Net file, the assemblyinfo. VB file will be used. The assembly configuration file can reference A. SNK file to save the key with a strong name.
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 name1_tool (sn.exe. The strong name tool is one of the SDK binary files that we can find in the. NET Framework installation path. 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 shown below:
[Assembly: assemblykeyfileattribute (@ "yourkeypair. SNK")]
Note that Visual Basic. NET is used to find the key file in the directory containing Visual Studio solution, while the C # compiler searches for the key file in the directory containing the binary file. Therefore, we can use this attribute to adjust the path we are using or place the key file in a suitable folder.
In any subsequent re-generation, the Assembly name will change. At the same time, when the old appdomain request ends, the old assembly will be deleted.
The app_code Folder does not only contain class files. In particular, it can contain and can automatically process XSD files representing the data architecture. When you add an XSD file to this folder, the compiler parses it into a dataset class with a type and adds it to the application scope. In ASP. NET 1. X, this job is directed by Visual Studio .netand completed by a command line program (xsd.exe.
Note: When registering a component (for example, a custom server control or a custom HTTP handler) using the web. config file, you must 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, you only need to ignore the assembly information and specify the complete class name. If no collation set is specified, the ASP. NET runtime attempts to load the class from any mounted assembly, including the Assembly dynamically created for the app_code folder.
4. app_data folder
The app_data folder should contain the local data storage of the application. It usually contains data storage in the form of files (such as Microsoft Access or Microsoft SQL Server express database, XML files, text files, and any other files supported by the application. The content of this folder cannot be processed by ASP. NET. This folder is the default location for ASP. NET providers to store their own data.
Note: by default, ASP. NET accounts are granted full access to folders. If you happen to change your ASP. NET account, make sure that the new account is granted read/write access to the folder.
5. app_globalresources folder
Like other applications, ASP. NET applications can also use resources, and resources should generally be used. Resources are an effective way to isolate the localized part of the application user interface. Generally, resources are program-related unexecutable texts. Typical resources include images, icons, text, and ancillary files, but any serializable object can also be seen as a resource. Application resources are stored outside the application so that they can be re-compiled and replaced without affecting or re-compiling the application itself.
An ASP. NET application requires a main assembly to save the default or neutral resources of the application. In addition, many ancillary assemblies must be deployed, each containing localization resources of a culture that we need to support. In ASP. NET 1.x, it is a little troublesome to compile resources in an assembly. You need to manually compile XML-based resource files (those with. Res extensions) into. Resources binary files. These files can be embedded into a. Net executable file or compiled into ancillary assembly. Use the resource file Generator program resgen.exe to convert text and XML-based resource files into. resource files. The resource file name follows the naming conventions of basename. culturename. Resource, where basename is usually the name of the application:
Resgen.exe proaspnetw.resx proaspnetw.it. Resources
After the. Resource file is created, it should be embedded into a set of programs, and can even be used as a resource container. To embed a resource file into an affiliated program concentration, you can use the connector tool (al.exe) of the program set ). On the command line, it indicates the culture used by the Assembly (for example, it in the example below, which represents Italy) and the name.
Al/out: proaspnetw.resources. dll/C: It/embed: proaspnetw.it. Resources
After the affiliated Assembly is compiled, they will have the same name. Deploy them in different subdirectories and name them by culture.
Fortunately, for ASP. NET 2.0, the era of ancillary assembly is gone forever. More accurately, the affiliated Assembly still exists, but because app_globalresources retains folders, they have become a thing of the past for developers.
Any located. resx file in this folder is automatically compiled into a subsidiary program set .. The resx file name contains cultural information to help generate an assembly in the ASP. NET Runtime Library environment. The following files: resources. resx, resources. It. resx, resources. Fr. resx generate neutral assembly and ancillary Assembly suitable for Italian and French (French) cultures. If no specific language is required, the neutral assembly is the default cultural resource.
The resource file in the app_globalresources folder is the global resource of the application, so it can be referenced from any page. Compared with ASP. NET 1.x, resource reading results are greatly simplified:
<Asp: Label runat = "server" text = "<% $ resources: resxfile, myresname %>"/>
You can use the latest $-expression, called resources, to bind a global resource as a declaration (Chapter 1 will detail $-expression ). This expression includes two parameters: the name of the. resx resource file (without an extension) and the name of the resource to be retrieved. Use the following code to access resources programmatically:
Httpcontext. getglobalresourceobject (resxfile, myresname)
Both parameters are strings and have the same effect as the $-expression parameters. In addition, the implementation of $-expression resources internally uses getglobalresourceobject.
6. app_localresources folder
The app_localresources folder is located in a subdirectory that contains some ASP. NET pages. This folder can be filled with the. resx file named in the top-level directory in the directory structure. Assume that the parent folder contains test. aspx, you can find some available resource files in the app_localresources folder as follows: test. aspx. resx, test. aspx. it. resx and test. aspx. fr. resx. Obviously, the resources stored in the above files only have an impact on the test. ASPX page, so they can only be seen on the linked page (they can be used ).
How can I access a page's unique resources? For programming access, you can use the following code:
Httpcontext. getlocalresourceobject ("/proaspnet20/respage. aspx", "pageresource1.title ")
The third parameter indicates the virtual path of the page, and the third parameter indicates the Resource Name. For declarative access, use the meta: resourcekey attribute. For example,
<Asp: button runat = "server" meta: resourcekey = "buttonresource1"/>
This statement associates a unique resource key with a specific button instance. Partial file. resx contains entries in the prefix. Name format, where prefix is the resource key, and name is the property name on the bound control. To assign the button a localized title (Text attribute), you only need to create a buttonresource1.text entry in the resource file.
The resource files in local and global resource folders are compiled to create classes for the affiliated Assembly. The final result is that the developer creates the. resx file and tests the page. The ASP. NET compilation mechanism will complete other work.
7. app_themes folder
The app_themes folder defines the topic for the ASP. NET control. The topic contains a folder in the app_themes folder. According to the definition, a topic is a group of files with style information. The file content in the theme folder is compiled to generate a class, which is called by the page to set the theme control style programmatically.
The app_themes folder lists the local topics of the application. The application can also inherit the global themes defined in the following folders:
% WINDOWS % \ Microsoft. NET \ framework \ [version] \ ASP. netclientfiles \ themes
From the compilation perspective, there is no difference between a global topic and a local topic. If a topic with a given name exists both the local topic of the application and the global topic of the server machine, the local topic is preferred.
8. app_webreferences folder
In Visual Studio. NET 2003, an ASP. NET application that needs to access web services will obtain the corresponding. WSDL file through the "add web reference" dialog box. The Web Service Description Language (WSDL) Document of web services is not enough for using web services from pages. The ASP. NET page is eventually a Managed class and needs to communicate with another Managed class. Therefore, a Web Service is encapsulated by a proxy class. This proxy class is created by visual studiousing the command line tool wsdl.exe service. This proxy class should include as many methods as possible as the web method of the web service provider, and it combines any custom data type defined by the public interface of the web service.
Developers do not have to pay a lot for this operation. However, developers obviously need to rely on Visual Studio to generate proxy classes. Isn't it easier and easier to directly place the. WSDL file somewhere in the application's directory tree and let ASP. NET handle other tasks? This is exactly what the app_webreferences folder is going to do.
It identifies the. WSDL files used to describe the bound web service and generates runtime proxy classes so that ASP. NET pages can place type-Safe Web service calls. The app_webreferences folder can contain subfolders. The name of the sub-Folder drives the namespace of the proxy class obtained at the end, while the WSDL file defines the class name. For example, the samples. WSDL file and the prosaspnet20 sub-folder will create a proxy class called proaspnet#samples. The Assembly created in this dynamic state is called app_webreferences.xxx.dll, where XXX is a random character sequence.
Folder name |
File Type |
Note |
Bin |
. Dll |
Contains any pre-generated assembly required by the application |
App_browsers |
. Browser |
Contains the browser definition file specific to the application. ASP. NET uses it to identify various browsers and determine their functions |
App_code |
. CS,. VB,. XSD, custom file type |
Contains the source files of classes compiled as part of the application. When the page is requested, ASP. NET compiles the code in this folder. The code in this folder is automatically referenced in the Application |
App_data |
. Mdb,. MDF,. xml |
Contains Microsoft Office Access and SQL express files and XML files or other data storage |
App_globalresources |
. Resx |
Resource files included in the localized application for programming |
App_localresources |
. Resx |
Resource files containing page ranges |
App_themes |
. Skin,. CSS,. XSL, and ancillary files |
Contains a set of files that define the appearance of ASP. NET pages and controls |
App_webreferences |
. WSDL |
Contains the WSDL file used to generate the proxy class and other files related to the use of web services in the application. |