Full rewrite of the portfolio site from Next.js 14 to .NET 10: - ASP.NET Core 10 Razor Pages, no Node.js dependency - EF Core 10 + SQLite (same schema as before — data survives upgrade) - Cookie authentication (same single-password model) - Resend contact form via HttpClient - Bilingual FA/EN via locale cookie + BasePageModel - All UI ported to Razor Pages with Tailwind CDN + custom CSS - Vanilla JS: particles, typewriter, cursor, animations, portfolio modal - Dockerfile: SDK 10.0-alpine → aspnet 10.0-alpine (no npm/Node needed) - CI/CD: dropped NPM_TOKEN, ADMIN_SESSION_SECRET — pure dotnet publish Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SoroushAsadi.Data;
|
||||
using SoroushAsadi.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// --- Razor Pages ---
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
// --- Authentication (single-password cookie auth) ---
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(opt =>
|
||||
{
|
||||
opt.LoginPath = "/Admin/Login";
|
||||
opt.LogoutPath = "/Admin/Logout";
|
||||
opt.Cookie.Name = "sa_admin";
|
||||
opt.Cookie.HttpOnly = true;
|
||||
opt.Cookie.SameSite = SameSiteMode.Lax;
|
||||
opt.ExpireTimeSpan = TimeSpan.FromDays(7);
|
||||
opt.SlidingExpiration = true;
|
||||
});
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
// --- EF Core + SQLite ---
|
||||
var dataDir = builder.Configuration["DataDir"]
|
||||
?? Path.Combine(builder.Environment.ContentRootPath, "data");
|
||||
Directory.CreateDirectory(dataDir);
|
||||
Directory.CreateDirectory(Path.Combine(dataDir, "uploads"));
|
||||
|
||||
builder.Services.AddDbContext<AppDbContext>(opt =>
|
||||
opt.UseSqlite($"Data Source={Path.Combine(dataDir, "cms.db")}"));
|
||||
|
||||
// --- App services ---
|
||||
builder.Services.AddScoped<ContentService>();
|
||||
builder.Services.AddScoped<AuthService>();
|
||||
builder.Services.AddScoped<EmailService>();
|
||||
builder.Services.AddHttpClient<EmailService>();
|
||||
|
||||
// --- Static file serving for /data/uploads ---
|
||||
builder.Services.Configure<StaticFileOptions>(opt => { });
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Run EF migrations on startup (creates DB if missing)
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
db.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
app.UseStatusCodePagesWithReExecute("/Error/{0}");
|
||||
app.UseStaticFiles();
|
||||
|
||||
// Serve uploaded files from /data/uploads under /uploads/*
|
||||
var uploadsPath = Path.Combine(dataDir, "uploads");
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(uploadsPath),
|
||||
RequestPath = "/uploads"
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapRazorPages();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user