DEV Community

Cover image for CodeBehind 2.0 is Released; ASP.NET Core Alternative
elanatframework
elanatframework

Posted on • Updated on

CodeBehind 2.0 is Released; ASP.NET Core Alternative

Is there an alternative to ASP.NET Core?

Yes, the Elanat team's CodeBehind framework is a competitor to the default structure of cshtml pages in ASP.NET Core. The CodeBehind framework supports the C# programming language and still runs on .NET Core. The CodeBehind framework is modular and is faster than the default ASP.NET Core.

Version 2.0

We at Elanat team did a lot of testing on the CodeBehind framework after the release of version 1.9 and fixed the existing defects before releasing version 2.0 so that version number 2.0 would be a stable version.

ViewData in Controller and Model

One of the most important new features in CodeBehind framework version 2.0 is the ability to add values to ViewData through the controller and model.

Example of adding data to ViewData in the controller section:

using CodeBehind;

namespace YourProjectName
{
    public partial class AboutPageController : CodeBehindController
    {
        public void PageLoad(HttpContext context)
        {
            ViewData.Add("title", "About");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Example of receiving data from ViewData in the controller section:

Razor syntax

@page
controller YourProjectName.AboutPageController
<!DOCTYPE html>
<html>
<head>
    <title>@ViewData.GetValue("title")</title>
</head>
<body>
...
Enter fullscreen mode Exit fullscreen mode

Standard syntax

<%@ Page Controller="YourProjectName.AboutPageController" %>
<!DOCTYPE html>
<html>
<head>
    <title><%=ViewData.GetValue("title")%></title>
</head>
<body>
...
Enter fullscreen mode Exit fullscreen mode

Download API

From version 2.0 onwards, it is possible to download files from the executive pages.

You can use the Download method to download files after users request them on the view pages; the Download method has an input argument of the file path and can be accessed from all three sections: view, controller, and model.

Example:

Download("C:\\image.png");
Enter fullscreen mode Exit fullscreen mode

Global template

Global template are a new feature of the CodeBehind framework. All view pages call this template.

It is recommended to use only template blocks in the global format.

This template is called in code_behind/global_template.astx path.

possibility of adding more templates

From now on, you can add more templates; It is enough to separate the paths of the templates with the semicolon character (;).

Razor syntax example:

@page
@template "/page/template/template1.astx;/page/template/template2.astx;/page/template/template3.astx"
Enter fullscreen mode Exit fullscreen mode

Standard syntax example:

<%@ Page Template="/page/template/template1.astx;/page/template/template2.astx;/page/template/template3.astx" %>
Enter fullscreen mode Exit fullscreen mode

cshtml files

In the options file, we added an option to support cshtml files so that users of the CodeBehind framework can easily distinguish the codes of the view section with code highlighters.

Options file in CodeBehind 2.0

[CodeBehind options]; do not change order
view_path=wwwroot
move_view_from_wwwroot=true
rewrite_aspx_file_to_directory=false
access_aspx_file_after_rewrite=false
ignore_default_after_rewrite=true
start_trim_in_aspx_file=true
inner_trim_in_aspx_file=true
end_trim_in_aspx_file=true
set_break_for_layout_page=true
+convert_cshtml_to_aspx=false
Enter fullscreen mode Exit fullscreen mode

You can code in these files with razor syntax and standard syntax.
cshtml files will be available with aspx extension after compilation.
For default cshtml pages, the name should be Default.cshtml; So pages named Index.cshtml will not be the default route.

Please note that these files must not be added to projects in Visual Studio; The reason for this is that, in addition to the CodeBehind framework, these pages are also compiled in the default .NET mode and can create unstable situation and security risk conditions.
Also note that the default code highlighter of Visual Studio may in some cases have unnecessary errors from cshtml pages based on the CodeBehind framework.

Default pages after first run

In this version, if you run CodeBehind for the first time without the wwwroot directory, a ready default page will be created including a layout, header and footer.

Image description

Related links

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

Get CodeBehind from NuGet:
https://www.nuget.org/packages/CodeBehind/

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

Top comments (0)