If you are developing a web application, and when are trying to add a Class File to the project Visual Studio will ask a confirmation like “You are attempting to add a special file type (class) to an ASP.NET Web site. In general, to use this type of item in your site, you should place it in the ‘App_Code’ folder. Do you want to place the file in the ‘App_Code’ folder?” – If you say yes, it will create(if not exists) an App_Code folder and place the class file in this folder. The App_Code is an ASP.Net special folder introduced in ASP.Net 2.0 onwards, it acts as the BIN folder, where you can store source files, which will be compiled in runtime. You can find more details about App_Code folder in MSDN : Shared Code Folders in ASP.NET Web Sites.
Few days back I created a custom contol in App_Code folder, and I couldn’t found any way to add in my aspx page. After doing some search I found two ways to do it.
- Directly specifying App_code folder in ASPX Page.
- Registering the Control to application via Web.Config.
<%@ Register TagPrefix="dotnetthoughts" Assembly="__Code" Namespace="dotnetthoughts.Controls" %>
In this Assembly attribute specifies the control is from App_Code folder. And the Namespace specifies the Control name space.(By default when you are adding a Class file namespace won’t be there, you need to add a Namespace.)
<configuration>
<system.web>
<pages>
<controls>
<add namespace="dotnetthoughts.Controls" tagPrefix="dotnetthoughts"/>
</controls>
</pages>
</system.web>
</configuration>
In this you don’t need to specify the control is loading from App_Code folder. Hopes it will be useful.