
Using the App_Code Folder for Testing Controls
You can use the dynamic compilation feature of ASP.NET 2.0 to test controls without compiling them into an assembly manually.
To put controls in the App_Code folder
Create an App_Code folder under the root folder of your Web site.
Copy the source files for the controls and related classes into the App_Code folder.
If you previously added an assembly for the control to the Bin folder, delete it.
Note: |
|---|
You can either pre-compile a control into an assembly and place the assembly in the Bin folder or place the control's source file in the App_Code folder. If you add the control to both folders, the page parser will not be able to resolve a reference to the control in a page and will generate an error.
|
Change the entry under the controls section in the Web.config file to the following highlighted entry, which maps the control's namespace to a tag prefix:
|
<controls>
<add tagPrefix="aspSample"
namespace="Samples.AspNet.CS.Controls">
..</add>
</controls>
|
|
<controls>
<add tagPrefix="aspSample"
namespace="Samples.AspNet.VB.Controls">
..</add>
</controls>
|
For more information, see @ Register.
Request the .aspx pages in a Web browser.
If you place the source files for the QuickContacts and ContactCollectionEditor classes from Web Control Collection Property Example in the App_Code folder, you must also add a reference to the System.Design assembly in the compilation section of the Web.config file. This reference requires the fully qualified assembly name of the System.Design assembly. You can get the information required for the fully qualified name by running the Global Assembly Cache Tool (Gacutil.exe) that ships with the Windows Software Development Kit (SDK), using the following syntax:
Note: |
|---|
To run the .
Global Assembly Cache Tool (Gacutil.exe) from the command line, the Windows environment PATH variable of your computer must include the path to your .NET Framework installation. In Windows, right-click My Computer, click Properties, click the Advanced tab, and then click the Environment Variables button. In the System variables list, double-click the Path variable. In the Variable value text box, add a semicolon (;) to the end of the existing values in the text box, and then type the path of your .NET Framework installation. The .NET Framework is usually installed in the Windows installation folder at \Microsoft.NET\Framework\versionNumber.
|
The tag you add to the compilation section of the Web.config file is similar to the highlighted section in the following example. However, you must replace the values of the Version and the PublicKeyToken attributes with the values returned by the Gacutil.exe tool.
|
<compilation >
<assemblies>
<add assembly="System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
|
Note: |
|---|
If you are using an integrated development environment, the designer might provide a simpler technique for adding an assembly reference to the Web.config file. For example, in Visual Studio 2005, if you right-click the Web site name in Solution Explorer and click
Add Reference in the shortcut menu, you can use a dialog box that allows you to select an assembly to add. When you select the assembly, the designer automatically adds the relevant entry to the Web.config file.
|