CodeBehind is a modern full-stack web framework under ASP.NET Core. CodeBehind was developed by Elanat in 2023 and competes with Microsoft's default web frameworks (ASP.NET Core MVC and Razor Pages and Blazor). CodeBehind is an engineering masterpiece that simultaneously provides the possibility of development based on MVC, Model-View, Controller-View, only View and Web-Forms. The type of structure and naming in CodeBehind is a nostalgia that reminds of former Microsoft Web-Forms. CodeBehind has nothing to do with the old web-form in .NET. In CodeBehind, you can use Razor syntax (@Razor) and standard syntax (<%=Standard%>). CodeBehind is .NET Diamond! In many scenarios, CodeBehind performs better than the default frameworks in ASP.NET Core.
$ dotnet add package CodeBehindThis 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 Code-Behind without coding in the view.
We (elanat.net) will use Code-Behind to migrate the Elanat framework from .NET Standard to the latest .NET Core versions; during the migration, if we need more convenient coding and more maneuvers to do coding, we will add new features to Code-Behind and provide newer versions of Code-Behind with more features.
Model File: Default.aspx.Model.cs using CodeBehind;
namespace YourProjectName.wwwroot { public partial class DefaultModel : CodeBehindModel { public string PageTitle { get; set; } public string BodyValue { get; set; } } }
View File: Default.aspx <%@ Page Controller="YourProjectName.wwwroot.DefaultController" Model="YourProjectName.wwwroot.DefaultModel" %>
<%=model.PageTitle%> <%=model.BodyValue%>Controler File: Default.aspx.Controller.cs using CodeBehind;
namespace YourProjectName.wwwroot { public partial class DefaultController : CodeBehindController { public DefaultModel model = new DefaultModel();
public void PageLoad(HttpContext context)
{
if (!string.IsNullOrEmpty(context.Request.Form["btn_Add"]))
btn_Add_Click();
model.BodyValue = "HTML Body";
View(model);
}
}
private void btn_Add_Click()
{
model.PageTitle = "btn_Add Button Clicked";
}
}
Program File: Program.cs using CodeBehind; using SetCodeBehind;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); }
CodeBehindCompiler.Initialization();
app.Run(async context => { CodeBehindExecute execute = new CodeBehindExecute(); await context.Response.WriteAsync(execute.Run(context)); });
app.UseHttpsRedirection(); app.UseStaticFiles();
app.UseRouting();
app.Run();