CodeBehind 1.5.0
Prefix ReservedSee the version list below for details.
dotnet add package CodeBehind --version 1.5.0
NuGet\Install-Package CodeBehind -Version 1.5.0
<PackageReference Include="CodeBehind" Version="1.5.0" />
paket add CodeBehind --version 1.5.0
#r "nuget: CodeBehind, 1.5.0"
// Install CodeBehind as a Cake Addin #addin nuget:?package=CodeBehind&version=1.5.0 // Install CodeBehind as a Cake Tool #tool nuget:?package=CodeBehind&version=1.5.0
Code_behind
Code-Behind 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 Code-Behind without coding in the view.
CodeBehind is a stable and reliable framework; Elanat is the most powerful .NET system implemented using the CodeBehind framework. https://github.com/elanatframework/Elanat
One of the great features that Code-Behind 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 Code-Behind 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();
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>
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; }
}
}
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)
{
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));
+ await context.Response.CompleteAsync();
});
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
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.
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 Code-Behind:
aspx page
<%@ Page Controller="YourProjectName.wwwroot.DefaultController" Model="YourProjectName.wwwroot.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.wwwroot
{
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.
Enjoy Code-Behind, but be careful not to loop the program! (Don't call pages that call the current page).
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 | 147 | 11/10/2024 |
3.7.2 | 191 | 10/22/2024 |
3.7.1 | 121 | 10/19/2024 |
3.7.0 | 120 | 10/14/2024 |
3.6.1 | 244 | 9/30/2024 |
3.6.0 | 301 | 9/9/2024 |
3.5.0 | 114 | 9/4/2024 |
3.4.1 | 198 | 8/27/2024 |
3.4.0 | 141 | 8/27/2024 |
3.3.0 | 156 | 8/24/2024 |
3.2.2 | 141 | 8/23/2024 |
3.2.1 | 159 | 8/16/2024 |
3.2.0 | 122 | 8/15/2024 |
3.1.0 | 125 | 8/15/2024 |
3.0.0 | 204 | 7/30/2024 |
2.9.2 | 106 | 7/24/2024 |
2.9.1 | 99 | 7/24/2024 |
2.9.0 | 98 | 7/22/2024 |
2.8.0 | 205 | 6/29/2024 |
2.7.1 | 256 | 6/16/2024 |
2.7.0 | 132 | 6/16/2024 |
2.6.0 | 139 | 6/10/2024 |
2.5.1 | 104 | 6/9/2024 |
2.5.0 | 207 | 5/20/2024 |
2.4.3 | 147 | 5/12/2024 |
2.4.2 | 182 | 3/31/2024 |
2.4.1 | 107 | 3/31/2024 |
2.4.0 | 189 | 3/5/2024 |
2.3.0 | 124 | 2/17/2024 |
2.2.0 | 147 | 1/26/2024 |
2.1.2 | 162 | 1/6/2024 |
2.1.1 | 117 | 1/5/2024 |
2.1.0 | 110 | 1/5/2024 |
2.0.0 | 173 | 12/23/2023 |
1.9.3 | 136 | 12/18/2023 |
1.9.2 | 153 | 12/9/2023 |
1.9.1 | 122 | 12/2/2023 |
1.9.0 | 137 | 11/30/2023 |
1.8.1 | 132 | 11/27/2023 |
1.8.0 | 128 | 11/26/2023 |
1.7.0 | 175 | 10/18/2023 |
1.6.1 | 144 | 10/18/2023 |
1.6.0 | 145 | 10/18/2023 |
1.5.2 | 164 | 9/28/2023 |
1.5.1 | 157 | 9/19/2023 |
1.5.0 | 134 | 9/13/2023 |
1.4.3 | 159 | 9/3/2023 |
1.4.2 | 168 | 8/30/2023 |
1.4.1 | 186 | 8/26/2023 |
1.4.0 | 139 | 8/23/2023 |
1.3.2 | 151 | 8/12/2023 |
1.3.1 | 156 | 8/12/2023 |
1.3.0 | 151 | 8/12/2023 |
1.2.0 | 177 | 7/24/2023 |
1.1.1 | 175 | 7/4/2023 |
1.1.0 | 167 | 7/3/2023 |
1.0.0 | 212 | 6/30/2023 |