Why ASPX pages in WebForm Project cannot invoke classes under the Appcode folder (use of ASP. NET special folders)

Source: Internet
Author: User
Tags sql server express wsdl

App_code only works with website types.

The. cs file created under App_Code is simply "content" and not code.
You can set the file to "compile".

Other special folders

1. Bin folder
The Bin folder contains the deployable threads required by the application for controls, components, or any other code that needs to be referenced
The sequence set. Any. dll files that exist in the directory are automatically linked to the application.


2. App_Browser folder

The optional folder contains the. browser file.. browser file Description Browser (whether it is a mobile device browser, or
Is the feature and functionality of the desktop browser.


3. App_Code folder

The App_Code folder is exactly at the root of the Web application and its storage should be dynamic as part of the application
The compiled class file. These class files are automatically linked to the application without the need to add any explicit directives to the page or
Declaration to create a dependency. class files placed in the App_Code folder can contain any recognizable ASP.
---custom controls, helper classes, build providers, business classes, custom providers, HTTP handlers, and more.

Note When you develop, changes to the App_Code folder cause the entire application to recompile. For large
Projects, which may be unpopular and time-consuming. To do this, we encourage you to modularize your code into different classes.
Library, organized by a logically related collection of classes. Most application-specific helper classes should be placed in the App_Code text
Folder.

All class files stored in the App_Code folder should use the same language. If the class file uses two or more languages
Written, you must create a subdirectory of a specific language to contain the classes written in each language. Once these are organized according to the language
class file, you will add a setting for each subdirectory in the Web. config file:

<compilation>

<codeSubDirectories>

<add directoryname= "Vbfolder"/>

</codeSubDirectories>

</compilation>

It is important that a language-specific subdirectory be registered in the Web. config file, otherwise, regardless of which folder they belong to
, all files under the App_Code folder will be compiled into a separate assembly. The above configuration script describes this
One scenario is that all C # files are placed in 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, then
You receive a compile error prompt.

Files in the App_Code root folder are compiled into App_code_xxx.dll assemblies, where xxx is a randomly generated character
Sequence. A file in a given subdirectory will be compiled into a dynamic creation named App_subcode_xxx_yyy.dll.
The built assembly, where XXX indicates the name of the subdirectory, and YYY is a sequence of random characters. Only in the application root
The,<codesubdirectories> section is not valid in the Web. config file in the directory.

Place a AssemblyInfo.cs file in the App_Code directory or any other subdirectory to create a strong named
The assembly. Obviously, if the folder contains visual Basic. NET file, you will use the
AssemblyInfo.vb file. An assembly configuration file can reference an. 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. Pass
You can obtain such a key pair by using the strong name (Strong name) tool (Sn.exe). The Strong Name tool is what we can
One of the sdkbinary found in the installation path of the. NET Framework. A key pair file usually has a. snk extension
Exhibition name. 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 to look for a key file in a directory that contains visual Studio solution.
The C # compiler looks for the key file in the directory that contains the binary. As a result, we use this property to adjust the
Path, or place the key file in the appropriate folder.

In any subsequent rebuilds, the name of the assembly changes. Meanwhile, the old AppDomain requests a knot
To delete the old assembly.

The App_Code folder does not contain only class files. In particular, it can contain and can automatically handle data structures that represent the
XSD file. When you add an XSD file to the folder, the compiler parses it into a typed
DataSet class and add it to the application scope. In ASP. 1.x, this work is done by the visual
Studio. NET Wizard, which is done using a command-line utility (Xsd.exe).

Note 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 name of the assembly that contains the code. If the component defines
In the App_Code folder, what name should be used to indicate the assembly? In this case, just ignore the assembly letter
and provide a complete class name. If no assembly is specified, the ASP. NET runtime will attempt to
The loaded assembly loads the class, including the assemblies that were created dynamically for the App_Code folder.

4. App_Data folder

The App_Data folder should contain the application's local data store. It usually takes a file (such as Microsoft
Access or Microsoft SQL Server Express databases, XML files, text files, and application support
Contains data stores in the form of any other file. The contents of this folder are not processed by ASP. This folder is an ASP.
The default location where the provider stores its own data.

Note The default ASP. NET account is granted full access to the folder. If it happens to change
Asp. NET account, make sure that the new account is granted read/write access to the folder.


5. App_GlobalResources folder

6. App_LocalResources folder

7. App_Themes folder

The App_Themes folder defines the theme for the ASP. Topic contains a folder under the App_Themes folder
。 By definition, a topic is a set of files with style information. The contents of the files in the theme folder are compiled to
into a class, and the class is programmed to set the style of the themed control programmatically by a page call.

The App_Themes folder lists the local topics for the application. The application can also inherit the full-file defined in the following folder
Board Theme:

%windows% "Microsoft.NET" Framework "[Version]" "Asp.netclientfiles" Themes

From a compilation perspective, there is no difference between a global theme and a local theme. If a topic of a given name exists, both the application process
The global theme of the server machine, the local theme takes precedence.

8. App_WebReferences folder

In Visual Studio. NET 2003, a Web application that requires access to the
Add Web References dialog box to get the corresponding. wsdl file. WSDL for Web Services (Web service Description
Language) documents, it is not enough to use Web services from a page. Asp. NET page is ultimately a managed class, and
You need to communicate with another managed class. Therefore, the Web service is wrapped by a proxy class. The proxy class is created by the visual
Studio is created using the command-line tool Wsdl.exe service. The proxy class contains as much as possible a Web method with the Web service
And it combines any custom data types defined by the common interface of the Web service.

This operation does not require the developer to pay a significant price. However, developers obviously have to rely on VisualStudio to
Generates the proxy class. If you can put the. wsdl file directly somewhere in the application's directory tree, and let ASP.
The rest of the task, isn't it easier and easier? This is exactly what the App_WebReferences folder has to do.
Things.

It identifies the. wsdl file that is used to describe the Web service being bound and generates a runtime proxy class so that the ASP.
Polygons can place calls to Web services in a type-safe manner. The App_WebReferences folder can contain subdocuments
Folder. The name of the subfolder drives the namespace of the last resulting proxy class, and the WSDL file defines the class name. For example
, the samples.wsdl file and the ProsAspNet20 subfolder will create a proxy called Proaspnet20.samples
Class. The dynamically created assembly is called App_WebReferences.xxx.dll, where xxx is a random word Fu She
Column.

Folder name
File type
Comments

Bin
. dll
Contains any pre-built assemblies required by the application

App_Browsers
. browser
Contains the application-specific browser definition file, ASP. NET uses it to identify browsers and determine their capabilities.

App_Code
. cs,. vb,. xsd, custom file types
The source file that contains the class that is compiled as part of the application. When the page is requested, ASP. NET to compile the folder
Code in the. The code in this folder is automatically referenced in the application

App_Data
. mdb,. mdf,. xml
Contains Microsoft Office access and SQLExpress files, as well as XML files or other data stores

App_GlobalResources
. resx
Contains resource files that are used programmatically in localized applications

App_LocalResources
. resx
Resource file containing the page range

App_Themes
. Skin,. CSS,. xsl, satellite files
Contains a set of files that define the appearance of the ASP. NET pages and controls

App_WebReferences
. wsdl

Why ASPX pages in WebForm Project cannot invoke classes under the Appcode folder (use of ASP. NET special folders)

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.