CodeBehind 1.6.0
Prefix ReservedSee the version list below for details.
dotnet add package CodeBehind --version 1.6.0
NuGet\Install-Package CodeBehind -Version 1.6.0
<PackageReference Include="CodeBehind" Version="1.6.0" />
paket add CodeBehind --version 1.6.0
#r "nuget: CodeBehind, 1.6.0"
// Install CodeBehind as a Cake Addin #addin nuget:?package=CodeBehind&version=1.6.0 // Install CodeBehind as a Cake Tool #tool nuget:?package=CodeBehind&version=1.6.0
Code_behind
CodeBehind library is a backend framework. This library is a programming model based on the MVC structure, which provides the possibility of creating dynamic aspx files (similar to .NET Standard) in .NET Core and has high serverside independence. Soon we will expand this project so that in future versions you can experience both MVC and CodeBehind without coding in the view.
CodeBehind is .NET Diamond!
In every scenario, CodeBehind performs better than the default structure in ASP.NET Core.
Programming in CodeBehind is simple. The simplicity of the CodeBehind project is the result of two years of study and research on back-end frameworks and how they support web parts.
CodeBehind story
First, CodeBehind was supposed to be a back-end framework for the C++ programming language; our project in C++ was going well, we built the listener structure and we were even able to implement fast-cgi in the coding phase for the Windows operating system. Windows operating system test with nginx web server was very stable and fast; but for some reason, we stopped working and implemented CodeBehind on .NET Core version 7.
Documents
Performance test in only view section in version 1.5.2 (ASP.NET Core VS CodeBehind)
CodeBehind training (On YouTube)
Elanat was created using CodeBehind
CodeBehind is a stable and reliable framework; Elanat is the most powerful .NET system implemented using the CodeBehind framework.
https://github.com/elanatframework/Elanat
CodeBehind advantages
CodeBehind is a flexible framework. CodeBehind inherits all the advantages of ASP.NET Core and gives it more simplicity, power and flexibility.
CodeBehind, like the default ASP.NET Core, supports multiple platforms, and in the test conducted by the Elanat team, it also has high stability on Linux.
CodeBehind occupies less memory resources (ram) than ASP.NET Core.
aspx pages are compiled in CodeBehind and their calling is done at a very high speed, so that the path of the aspx file is not even referred to during the calling.
One of the great features that CodeBehind gives you is the support for DLL libraries. You can add all the .NET Core DLL libraries that you have created into the bin directory located in wwwroot so that the CodeBehind will call all of them.
We added Code_behind in Nuget so that you can access it easily. You can use it in: https://www.nuget.org/packages/CodeBehind
How to add web part? First, copy your compiled project files to the desired path in wwwroot; then copy the main dll file to wwwroot/bin path. You can do the copy while the process is running in the method and then call the code below to compile without restarting the program.
// Recompile
CodeBehindCompiler.Initialization();
CodeBehindCompiler.CompileAspx();
Error detection
After running the project, CodeBehind will create a directory called code_behind
next to the wwwroot
directory. In this directory, the view class, which is made of aspx files, is kept. If there is any error in the aspx files, it will also be displayed in the views_compile_error.log
file.
Simple and structured MVC in CodeBehind
Note: All tutorials are updated based on the latest version of CodeBehind. Avoid installing previous versions and install the latest version. Version 1.0.0 does not support Default.aspx files for directories!
View File: Default.aspx
<%@ 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
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
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);
}
}
}
Program File: Program.cs
using CodeBehind;
using SetCodeBehind;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
+ CodeBehindCompiler.Initialization();
app.Run(async context =>
{
+ CodeBehindExecute execute = new CodeBehindExecute();
+ await context.Response.WriteAsync(execute.Run(context));
});
app.Run();
If you enter the value true in CodeBehindCompiler.Initialization(), as long as the CodeBehindLastSuccessCompiled.dll.tmp file exists next to the main dll files of the program, recompilation will not be done. Doing this makes the response speed of the requests high after the first request since the program goes to sleep.
CodeBehindCompiler.Initialization(true);
Note : If you configure the Program.cs class like this, any changes in the aspx files, or adding new web parts or removing web parts, requires deleting the CodeBehindLastSuccessCompiled.dll.tmp file.
You can use the Write method in the model and controller classes; the Write method adds a string value to the ResponseText attribute; you can also change the values of the ResponseText attribute by accessing them directly.
In the controller class, there is an attribute named IgnoreViewAndModel attribute, and if you activate the IgnoreViewAndModel attribute, it will ignore the values of model and view and you will only see a blank page; this feature allows you to display the values you need to the user and avoid multiple redirects and transfers.
Note: If you have set the name of a model in the aspx file, You must make sure to call View(ModelName) in the controller class at the end of the method or set the value of IgnoreViewAndModel to true.
It is not necessary to follow the MVC pattern
In addition to the MVC pattern, you can expand your systems in the form of only View or Controller and View or Model and View.
MVC and V and VC and MV patterns are supported in CodeBehind.
It is not necessary to have a controller and a model, you can code in an aspx page.
Only View example
View
<%@ Page %>
<%Random rand = new Random();%>
<div>
<h1>Random value: <%=rand.Next(1000000)%></h1>
</div>
View and Model without Controller example
View
<%@ Page Model="YourProjectName.DefaultModel" %>
<div>
<b><%=model.Value1%></b>
<br>
<b><%=model.Value2%></b>
</div>
Model
using CodeBehind;
namespace YourProjectName
{
public partial class DefaultModel : CodeBehindModel
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public TestModel()
{
Value1 = "text1";
Value2 = "text2";
}
}
}
Examples of development
In aspx pages, you will access HttpContext with context.
<%@ Page %>
<% string HasValue = (!string.IsNullOrEmpty(context.Request.Query["value"]))? "Yes" : "No"; %>
<div>
<h1>Exist value in querystring? <%=HasValue%></h1>
<hr>
<b>value is: <%=context.Request.Query["value"].ToString()%></b>
</div>
To receive the information sent through the form, you can follow the instructions below:
public DefaultModel model = new DefaultModel();
public void PageLoad(HttpContext context)
{
if (!string.IsNullOrEmpty(context.Request.Form["btn_Add"]))
btn_Add_Click();
View(model);
}
private void btn_Add_Click()
{
model.PageTitle = "btn_Add Button Clicked";
}
The following example shows the power of CodeBehind:
aspx page
<%@ Page Controller="YourProjectName.DefaultController" Model="YourProjectName.DefaultModel" %><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title><%=model.PageTitle%></title>
</head>
<body>
<%=model.LeftMenuValue%>
<div class="main_content">
<%=model.MainContentValue%>
</div>
<%=model.RightMenuValue%>
</body>
</html>
Controller class
using CodeBehind;
namespace YourProjectName
{
public partial class DefaultController : CodeBehindController
{
public DefaultModel model = new DefaultModel();
public void PageLoad(HttpContext context)
{
model.PageTitle = "My Title";
CodeBehindExecute execute = new CodeBehindExecute();
// Add Left Menu Page
model.LeftMenuValue = execute.Run(context, "/menu/left.aspx");
// Add Right Menu Page
model.RightMenuValue = execute.Run(context, "/menu/right.aspx");
// Add Main Content Page
model.MainContentValue = execute.Run(context, "/pages/main.aspx");
View(model);
}
}
}
Each of the pages left.aspx, right.aspx and main.aspx can also call several other aspx files; these calls can definitely be dynamic and an add-on can be executed that the kernel programmers don't even know about.
You can also call a page without specifying an HttpContext. You should note that query string and HttpContext data are not supported in this method.
CodeBehindExecute execute = new CodeBehindExecute();
model.MainContentValue = execute.Run("/pages/main.aspx");
You can even call pages with query strings.
model.MainContentValue = execute.Run(context, "/pages/main.aspx?template=1");
You can also call a path that is determined at runtime and may change over time.
string MainPage = Pages.GetDefaultPage();
model.MainContentValue = execute.Run(context, MainPage);
Enjoy CodeBehind, but be careful not to loop the program! (Don't call pages that call the current page)
Web part in CodeBehind
In CodeBehind, the physical executable pages (aspx) are placed in the root path, and this makes the program structured.
CodeBehind supports web parts; web parts are like other parts of the project and include aspx files.
To add the web part in CodeBehind, just put the project files in 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.
In CodeBehind, the structure of web parts is the same as the structure of the main project; your main project includes aspx pages, dll files, and other client-side files (css, js, images, etc.); web parts in CodeBehind also include aspx pages, dll files and other client side files.
The project created by using CodeBehind is automatically a modular project, that is, it has the ability to add web parts. In addition, each web part can be used in other projects.
The system built with CodeBehind is also a web part itself. Each web part can also be a separate system! The web part that adds the configuration of the Program.cs class is considered the main system.
CodeBehind stores the final values of its pages outside of the Response in the HttpContext; you can edit the output of the final values in the aspx pages before the answer. This gives you more control than ASP.NET Core.
CodeBehind produces understandable code, while the Controller part of ASP.NET Core is a messy and complex situation.
You will never experience the power that the CodeBehind framework gives you in ASP.NET Core.
.NET developers accept CodeBehind as part of the larger .NET ecosystem. Whatever benefits CodeBehind has belongs to the .NET community.
CodeBehind is similar to interpreted frameworks such as Django and Laravel, and programmers of interpreted programming language projects can easily program with CodeBehind.
Developers of interpretative frameworks can consider CodeBehind as an alternative.
ASP.NET Core VS CodeBehind; why should we use CodeBehind?
Many developers avoid ASP.NET Core and choose interpretive frameworks like Django and Laravel. And this is due to the complexities and weak default structure of ASP.NET Core and the need for complex configurations and controller classes with a chaotic and incomprehensible structure for novice programmers, as well as the difficulty of building a modular system.
Really, no matter what we tried, we couldn't find any advantages to using ASP.NET Core compared to CodeBehind; perhaps if we were to compare ASP.NET Core with frameworks such as Django and Laravel, we could introduce high execution speed and leading programming language C# as a measure of ASP.NET Core's superiority; but using CodeBehind will give us the same advantages.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.8.0 | 204 | 11/10/2024 |
3.7.2 | 194 | 10/22/2024 |
3.7.1 | 125 | 10/19/2024 |
3.7.0 | 124 | 10/14/2024 |
3.6.1 | 254 | 9/30/2024 |
3.6.0 | 302 | 9/9/2024 |
3.5.0 | 115 | 9/4/2024 |
3.4.1 | 199 | 8/27/2024 |
3.4.0 | 142 | 8/27/2024 |
3.3.0 | 157 | 8/24/2024 |
3.2.2 | 142 | 8/23/2024 |
3.2.1 | 160 | 8/16/2024 |
3.2.0 | 123 | 8/15/2024 |
3.1.0 | 126 | 8/15/2024 |
3.0.0 | 205 | 7/30/2024 |
2.9.2 | 107 | 7/24/2024 |
2.9.1 | 100 | 7/24/2024 |
2.9.0 | 99 | 7/22/2024 |
2.8.0 | 206 | 6/29/2024 |
2.7.1 | 257 | 6/16/2024 |
2.7.0 | 133 | 6/16/2024 |
2.6.0 | 140 | 6/10/2024 |
2.5.1 | 105 | 6/9/2024 |
2.5.0 | 208 | 5/20/2024 |
2.4.3 | 148 | 5/12/2024 |
2.4.2 | 183 | 3/31/2024 |
2.4.1 | 108 | 3/31/2024 |
2.4.0 | 190 | 3/5/2024 |
2.3.0 | 125 | 2/17/2024 |
2.2.0 | 148 | 1/26/2024 |
2.1.2 | 163 | 1/6/2024 |
2.1.1 | 118 | 1/5/2024 |
2.1.0 | 111 | 1/5/2024 |
2.0.0 | 174 | 12/23/2023 |
1.9.3 | 137 | 12/18/2023 |
1.9.2 | 154 | 12/9/2023 |
1.9.1 | 123 | 12/2/2023 |
1.9.0 | 138 | 11/30/2023 |
1.8.1 | 133 | 11/27/2023 |
1.8.0 | 129 | 11/26/2023 |
1.7.0 | 176 | 10/18/2023 |
1.6.1 | 145 | 10/18/2023 |
1.6.0 | 146 | 10/18/2023 |
1.5.2 | 165 | 9/28/2023 |
1.5.1 | 160 | 9/19/2023 |
1.5.0 | 135 | 9/13/2023 |
1.4.3 | 160 | 9/3/2023 |
1.4.2 | 169 | 8/30/2023 |
1.4.1 | 187 | 8/26/2023 |
1.4.0 | 140 | 8/23/2023 |
1.3.2 | 152 | 8/12/2023 |
1.3.1 | 157 | 8/12/2023 |
1.3.0 | 152 | 8/12/2023 |
1.2.0 | 178 | 7/24/2023 |
1.1.1 | 176 | 7/4/2023 |
1.1.0 | 168 | 7/3/2023 |
1.0.0 | 213 | 6/30/2023 |