update 18-09

fix UI vs redirect page
This commit is contained in:
2025-09-18 15:39:23 +07:00
parent 142f7afb18
commit f6cc0175e0
23 changed files with 807 additions and 302 deletions

View File

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AppLibs.Libs
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class AsyncGateAttribute : Attribute, IAsyncActionFilter
{
public async Task OnActionExecutionAsync(
ActionExecutingContext context,
ActionExecutionDelegate next)
{
var vr = context.HttpContext.Request.Query["vr"].ToString();
// Nếu có vr=cAsync hoặc vr=lAsync => cho chạy action (logic nặng)
if (vr == "cAsync" || vr == "lAsync")
{
await next();
return;
}
// Không có vr => return ViewAsync ngay, bỏ qua action
if (context.Controller is Controller c)
{
var result = await ControllerExtensions.ViewAsync(c);
context.Result = result; // short-circuit
return;
}
context.Result = new NotFoundResult();
}
}
}

View File

@ -7,6 +7,7 @@ using Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using AppLibs.Libs.Pages;
using System.Security.Cryptography;
using System.Runtime.CompilerServices;
namespace AppLibs.Libs
{
@ -152,6 +153,22 @@ namespace AppLibs.Libs
await viewResult.View.RenderAsync(viewContext);
return Regex.Replace(writer.ToString(), @"(?>[^\S ]\s*| \s{2,})", "").Trim();
}
}
public static async Task<string> ReadStaticPage(this Controller controller, string id)
{
var filePath = Path.Combine(Directory.GetCurrentDirectory(),
"Data", "page", $"{id}.html");
if (!System.IO.File.Exists(filePath))
throw new FileNotFoundException();
string htmlContent;
using (var reader = new StreamReader(filePath))
{
htmlContent = await reader.ReadToEndAsync();
}
return htmlContent;
}
}
}

View File

@ -23,7 +23,7 @@ namespace AppLibs.Libs
{
}
public LayoutAttribute(LayoutOptions option, string layoutName = "")
public LayoutAttribute(LayoutOptions option, string layoutName = "Async")
{
switch (option)
{