Skip to main content
Logo
There is a newer version of Contensis. Click to find out more and download the latest version.

Create an App_Code folder

The App_Code folder is a Special Code Folder for ASP.NET Websites, which can contain Code Files (e.g. .vb or .cs files) that the .NET Framework will automatically compile at run time.

The App_Code folder therefore works much like the Bin folder, except that you can store source code in it instead of compiled code. The App_Code folder and its special status in an ASP.NET Web application makes it possible to create custom classes and other source-code-only files and use them in your Web application without having to compile them independently.MSDN

app_code

Supporting VB and C# within App_Code

All code within the App_Code folder will get compiled into a single Assembly. The .NET runtime will determine which compiler to invoke based on the first file within the folder; therefore mixing languages within App_Code will cause compilation issues.

To support this, Contensis uses a convention whereby your published websites will follow a convention of using code sub folders to allow C# and VB files to co-exist, but in different folders within App_Code. 

app_code languages

Permissions

The App_Code folder is treated just like any other folder within Contensis in that you can manage Content Types and permissions on it. So you may want to restrict access to the folder to just your CMS System Administrators.

Warning: Please be aware that changes to your websites App_Code folder can have a serious impact on your website - and can lead to your website becoming unavailable. We would recommend thoroughly testing any changes on your preview site before approving the changes to go to your live environment.

If you make any mistakes during your site’s development within the App_Code folder, you can always roll back your changes in the version history.

Marketplace packages

This same convention will be followed by all packages on the marketplace. This means that all C# and VB Files will reside in their respective folders, so on installation of a Marketplace package, you should not run into any compilation run time errors.

Razor Views

You can also make use of your App_Code by using it to store any common functions that you seem to be replicating within your razor views.

Rather than duplicate logic across views, you could extract the reusable components into a C# or VB file within your App_Code and reference the function from there.