Please Check Out the CodeBehind Framework
Tags: dotnet, csharp, backend, webdev
Published: 2024-05-12 20:29:51

As you know, [Elanat content management system](https://elanat.net) is based on [CodeBehind framework](https://github.com/elanatframework/Code_behind) and created under .NET Core. We at Elanat team want to release the new version of Elanat CMS; Elanat CMS version 2.2 will release with the latest version of the CodeBehind framework.

The [CodeBehind framework](https://www.nuget.org/packages/CodeBehind/) is a powerful alternative to Razor Pages and the default MVC in ASP.NET Core; CodeBehind works up to 40% faster than them and has unique features.

Currently version 2.4.3 is the latest version of the CodeBehind framework. .NET developers are requested to check the latest version of the CodeBehind framework and report any undiscovered issues to us at Elanat.

### Only view example

View section: aspx page (razor syntax)
```html
@page
@{
    Random rand = new Random();
}

<div>
    <h1>Random value: @rand.Next(1000000)</h1>
</div>
```

View section: aspx page (standard syntax)
```html
<%@ Page %>
<%
    Random rand = new Random();
%>

<div>
    <h1>Random value: <%=rand.Next(1000000)%></h1>
</div>
```

### MVC example

View File: Default.aspx (razor syntax)
```html
@page
@controller YourProjectName.DefaultController
@model YourProjectName.DefaultModel
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@model.PageTitle</title>
</head>
<body>
    @model.BodyValue
</body>
</html>
```

View File: Default.aspx (standard syntax)
```html
<%@ Page Controller="YourProjectName.DefaultController" Model="YourProjectName.DefaultModel" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title><%=model.PageTitle%></title>
</head>
<body>
    <%=model.BodyValue%>
</body>
</html>
```

Model File: Default.aspx.Model.cs
```csharp
using CodeBehind;

namespace YourProjectName
{
    public partial class DefaultModel : CodeBehindModel
    {
        public string PageTitle { get; set; }
        public string BodyValue { get; set; }
    }
}
```

Controler File: Default.aspx.Controller.cs
```csharp
using CodeBehind;

namespace YourProjectName
{
    public partial class DefaultController : CodeBehindController
    {
        public DefaultModel model = new DefaultModel();
        public void PageLoad(HttpContext context)
        {
            model.PageTitle = "My Title";
            model.BodyValue = "HTML Body";
            View(model);
        }
    }
}
```

### CodeBehind Configure in ASP.NET Core
Program File: Program.cs
```diff
var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

+ SetCodeBehind.CodeBehindCompiler.Initialization();

app.Run(async context =>
{
+    CodeBehind.CodeBehindExecute execute = new CodeBehind.CodeBehindExecute();
+    await context.Response.WriteAsync(execute.Run(context));
});

app.Run();
```

### Documents

#### Programming
 - [Simple and structured MVC in CodeBehind](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/simple_and_structured_mvc_in_code_behind.md)
 - [It is not necessary to follow the MVC pattern](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/it_is_not_necessary_to_follow_the_mvc_pattern.md)
 - [Load aspx page finally result in another aspx page](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/load_aspx_page_finally_result_in_another_aspx_page.md)
 - [Examples of development](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/examples_of_development.md)
 - [Send data](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/send_data.md)
 - [Web part in CodeBehind](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/web_part_in_code_behind.md)
 - [Razor syntax reference for CodeBehind framework](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/razor_syntax_reference_for_code_behind_framework.md)
 - [Standard syntax reference for CodeBehind framework](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/standard_syntax_reference_for_code_behind_framework.md)
 - [Constructor method](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/constructor_method.md)
 - [HtmlData classes](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/html_data_classes.md)
 - [Template](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/template.md)
 - [Transfer template block data in ViewData](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/transfer_template_block_data_in_view_data.md)
 - [Layout](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/layout.md)
 - [Section](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/section.md)
 - [Error handling](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/error_handling.md)
 - [Options](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/options.md)
 - [Namespace and dll for CodeBehind view class](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/namespace_and_dll_for_code_behind_view_class.md)
 - [Error detection](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/error_detection.md)
 - [How to use CodeBehind?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_to_use_code_behind.md)
 - [Route configuration](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/route_configuration.md)
 - [Used with Razor Pages and ASP.NET Core MVC](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/used_with_razor_pages_and_asp_dot_net_core_mvc.md)
 - [Modularity in the default mode](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/modularity_in_the_default_mode.md)
 - [Modularity in the configuration of the controller in the route](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/modularity_in_the_configuration_of_the_controller_in_the_route.md)

#### API and applied methods
 - [Download file](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/download_file.md)
 - [Dynamic Model](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/dynamic_model.md)

#### Information
 - [New features on new versions](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/new_features_on_new_versions.md)
 - [How is the list of views finally made?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_is_the_list_of_views_finally_made.md)
 - [CodeBehind framework data](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/code_behind_framework_data.md)
 - [MVC architecture in CodeBehind](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/mvc_architecture_in_code_behind.md)
 - [Performance test, ASP.NET Core MVC and Razor Pages vs CodeBehind Framework in version 2.2](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/performance_test_asp_dot_net_core_mvc_and_razor_pages_vs_code_behind_framework_version_2.2.md)
 - [Performance test in only view section in version 1.5.2 (ASP.NET Core VS CodeBehind)](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/performance_test_in_only_view_section_version_1.5.2.md)
 - [CodeBehind story](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/code_behind_story.md)
 - [ASP.NET Core VS CodeBehind; why should we use CodeBehind?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/asp_dot_net_core_vs_code_behind.md)
 - [CodeBehind framework vs Code-Behind pattern](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/code_behind_framework_vs_code_behind_pattern.md)

#### Creating high-level systems
 - [How to create modular systems by CodeBehind framework?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_to_create_modular_systems_by_code_behind_framework.md)
 - [How to create scheduled task system by CodeBehind framework?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_to_create_scheduled_task_by_code_behind_framework.md)
 - [How to create startup system by CodeBehind framework?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_to_create_startup_system_by_code_behind_framework.md)
 - [How to create dynamic middleware system by CodeBehind framework?](https://github.com/elanatframework/Code_behind/blob/elanat_framework/doc/how_to_create_dynamic_middleware_by_code_behind_framework.md)

### Ready project

 - [Get ready project](https://github.com/elanatframework/Code_behind/tree/elanat_framework/ready_project)

### Related links

CodeBehind on GitHub:
https://github.com/elanatframework/Code_behind

CodeBehind in NuGet:
https://www.nuget.org/packages/CodeBehind/

CodeBehind page:
https://elanat.net/page_content/code_behind