DEV Community

Cover image for 8 Important Reasons Why CodeBehind Framework Is Better Than ASP.NET Core

Posted on

8 Important Reasons Why CodeBehind Framework Is Better Than ASP.NET Core

CodeBehind VS ASP.NET Core

What is CodeBehind framework?

CodeBehind is a new framework based on .NET Core version 7.0. The CodeBehind framework inherits all the features of .NET Core and gives it more simplicity and flexibility. CodeBehind framework is owned by Elanat.

CodeBehind is .NET diamond!

Please read this article to the end and if you think we have made a mistake somewhere, share it with us in the comments.
We welcome .NET programmers to review the CodeBehind framework and compare it to the default structure of cshtml pages in ASP.NET Core.

1- CodeBehind is simpler than ASP.NET Core

Model and controller in ASP.NET Core are complex and difficult to learn. Usually, the difficulty of learning and the complexity of development in ASP.NET Core is one of the negative points that are mentioned in articles that compare back-end frameworks.

Here is an example controller in the CodeBehind framework:

using CodeBehind;

namespace YourProjectName
    public partial class DefaultController : CodeBehindController
        public DefaultModel model = new DefaultModel();
        public void PageLoad(HttpContext context)
            model.BodyValue = "Hello World!";

Enter fullscreen mode Exit fullscreen mode

In ASP.NET Core, several methods such as OnGet(), OnPost() and Index() with return values to IActionResult cause confusion. While in CodeBehind there is only one PageLoad method without return. You don't need to return the view and just put the created instance of the model in the view method.

In ASP.NET Core, there is a complication in naming cshtml files and having the same name as controller and view methods (one of the worst ideas in programming!); but in CodeBehind this complexity is not there.

You can easily create MVC in CodeBehind framework.
The following example is an aspx page that has introduced the model and controller in the page attributes section.

View (aspx file)

+@controller YourProjectName.DefaultController
+@model YourProjectName.DefaultModel
<!DOCTYPE html>
Enter fullscreen mode Exit fullscreen mode

In the CodeBehind framework, views have priority over controllers and models. But that doesn't mean you can't call different views! You can add any view in any section of another view.

Add a page in the view section:

Enter fullscreen mode Exit fullscreen mode

Add a page in the controller section:

CodeBehindExecute execute = new CodeBehindExecute();
model.HeaderValue = execute.Run(context, "/header.aspx");
Enter fullscreen mode Exit fullscreen mode

Note: Adding a page in the model section is the same as the controller section.

To replace pages, you can create an empty view, or in the controller, you can set the IgnoreViewAndModel attribute to false to make the page empty.


IgnoreViewAndModel = true;
CodeBehindExecute execute = new CodeBehindExecute();
Write(execute.Run(context, "/main.aspx"));
Enter fullscreen mode Exit fullscreen mode

In the CodeBehind framework (like ASP.NET Core) you can easily create a headless system.

2- CodeBehind is modular

Every project built under the CodeBehind framework is modular, and the project itself is a module!

To add a new module to the current project, just create a new project under CodeBehind (no need to set the Program.cs file) and compile it; then it is enough to add the dll file of the new project in the wwwroot/bin path in the current project and place its aspx files in the desired path in wwwroot. only this!

A project created under CodeBehind

Implementing a modular structure in ASP.NET Core is complex.

3- CodeBehind is faster than ASP.NET Core

According to our latest tests, the CodeBehind framework is faster than the default cshtml framework in ASP.NET Core.

Interestingly, the superiority of CodeBehind over the default structure of ASP.NET Core is not a linear graph, and the higher the number of requests over time, the greater the graph of superiority is drawn towards CodeBehind.

This test was done in CodeBehind framework version 1.5.2. In version 1.5.2, we could not create pages in view only.
We admit right here that we made a mistake in determining the random interval and instead of 10 pages, 9 different pages are called (this has no role in the results and was announced only for your information).

You can see how to test and the results on this page:
Performance test in only view section in version 1.5.2 (ASP.NET Core VS CodeBehind)

In the future, we will retest the latest version of CodeBehind with ASP.NET Core.

4- In CodeBehind you have access to the output

You can get the output of any aspx page and add it after editing in any other page.
In the CodeBehind framework, you can add the output of aspx pages or add values directly to the output of Response in ASP.NET Core.

5- New ideas and initiatives

The Elanat team is constantly adding new ideas to the CodeBehind framework.

Change the view path
Set the view path wherever you like. You can put the views in the wwwroot directory or a directory outside of root.
You don't need to put the views in the Shared directory! Add views wherever you like and remove the aspx page from the direct access list by adding the break and islayout attributes.

Don't worry about the new aspx files in the wwwroot folder; it is transferred automatically!

The possibility of rewriting aspx files as a directory path (by removing the aspx extension).

One of the interesting ideas of the Elanat team for the CodeBehind framework is the possibility of rewriting the path of aspx files as a directory name. If you enable this option, paths leading to an aspx file without the aspx extension will be treated as the name of a directory.

No need to add an underline before the cshtml file name! Just add a file with the extension astx (external template) and add its path to the layout attribute in the page attributes section.

In a revolutionary initiative, the Elanat team provides a return templating structure that guarantees 100% separation of server-side code from the design part (like html).

Return template

One of the initiatives of the Elanat team in the CodeBehind framework is to add support for the CodeBehind constructor method for models and controllers. You can open parentheses in front of the model and controller class names and add the desired input arguments that you created in the CodeBehind constructor method.

6- You have more choices in CodeBehind than ASP.NET Core

Write in Razor (@Razor) or standard (<%=standard%>) syntax, you're free.
You can only use razor syntax in ASP.NET Core.
You will have full access to the HttpContext and can edit it in any section.
Build the pages as you like; MVC or model-view or controller-view or only view.
If you want, you can play the aspx pages in the root of the application or keep them in a path outside the root.
In CodeBehind, you can run web parts that make changes to aspx files. You can edit all aspx files during project execution and responding to users.

It is true that there are several free and open source CMS such as Umbraco and Orchard Core under ASP.NET Core; but even though CodeBehind is new, it comes with Elanat powerful CMS.

7- CodeBehind is completely based on the Code-Behind pattern

Even for loops and conditionals, you don't need to add server-side code in the view section.
You can use the HtmlData class in CodeBehind to stick with the View section based on the Code-Behind template.

Example for option tag:


<select name="framework">
Enter fullscreen mode Exit fullscreen mode


using CodeBehind;
using CodeBehind.HtmlData;

namespace YourProjectName
    public partial class DefaultController : CodeBehindController
        public DefaultModel model = new DefaultModel();

        public void PageLoad(HttpContext context)
            OptionTagCollection options = new OptionTagCollection();
            options.Add("code_behind", "CodeBehind", true);
            options.Add("asp_dot_net_core", "ASP.NET Core");
            options.Add("django", "Django");
            options.Add("laravel", "Laravel");
            options.Add("spring_boot", "Spring Boot");
            options.Add("ruby_on_rails", "Ruby on Rails");

            model.FrameworkOptionTags = options.GetString();

Enter fullscreen mode Exit fullscreen mode


<select name="framework">
    <option value="code_behind" selected>CodeBehind</option>
    <option value="asp_dot_net_core">ASP.NET Core</option>
    <option value="django">Django<option>
    <option value="laravel">Laravel</option>
    <option value="spring_boot">Spring Boot</option>
    <option value="ruby_on_rails">Ruby on Rails</option>
Enter fullscreen mode Exit fullscreen mode

Also you can also use return templates:

<div class="page-list">
  @#Tags={<a href="@#Href">@#PageName</a>}

@foreach (PageItem page in model.PageItemList)

@#Href{@(((page.Path == "main")? "/" : page.Path))}
Enter fullscreen mode Exit fullscreen mode

8- With CodeBehind, you can easily create high-level technologies

In CodeBehind, you can add as many middleware as you want without having to compile the project from scratch.

At the time of .NET Core presentation, Microsoft provided many articles to introduce middleware and their usage.

The middleware in CodeBehind is flexible and dynamic. Just run an aspx page!

Middleware in CodeBehind framework

The following resources show how to create high-level systems using the CodeBehind framework; please read these resources and think about implementing them in ASP.NET Core!

How to create modular systems by CodeBehind framework?

How to create scheduled task system by CodeBehind framework?

How to create startup system by CodeBehind framework?

How to create dynamic middleware system by CodeBehind framework?


The CodeBehind framework is a powerful alternative to default programming in ASP.NET Core. In the default structure of ASP.NET Core, a lot of attention is paid to solving errors, async programming, maintaining security and accessibility; but the CodeBehind framework focuses on maintaining simplicity, Improve performance, modular structure and new ideas.

Related links

CodeBehind on GitHub:

Get CodeBehind from NuGet:

CodeBehind page:

Top comments (0)