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 standard .NET) 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.
Model File: Default.aspx.Model.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; 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" %><!DOCTYPE html>
<html> <head> <meta charset="utf-8" /> <title><%=model.PageTitle%></title> </head> <body> <%=model.BodyValue%> </body> </html>Controler File: Default.aspx.Controller.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using CodeBehind;
namespace YourProjectName.wwwroot { 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();
// 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();
22.7K