diff --git a/src/JobsMedical.Web/Pages/Error.cshtml b/src/JobsMedical.Web/Pages/Error.cshtml index 6f92b95..8981863 100644 --- a/src/JobsMedical.Web/Pages/Error.cshtml +++ b/src/JobsMedical.Web/Pages/Error.cshtml @@ -14,6 +14,15 @@

} +@if (Model.AdminDetail is not null) +{ +
+ 🔧 جزئیات خطا (فقط برای ادمین) + @if (Model.AdminPath is not null) {
@Model.AdminPath
} +
@Model.AdminDetail
+
+} +

Development Mode

Swapping to the Development environment displays detailed information about the error that occurred. diff --git a/src/JobsMedical.Web/Pages/Error.cshtml.cs b/src/JobsMedical.Web/Pages/Error.cshtml.cs index f7061f5..ad865db 100644 --- a/src/JobsMedical.Web/Pages/Error.cshtml.cs +++ b/src/JobsMedical.Web/Pages/Error.cshtml.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -12,9 +13,24 @@ public class ErrorModel : PageModel public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + ///

The real exception — shown ONLY to a logged-in Admin, so production 500s can be + /// diagnosed without server-log access. Hidden from everyone else. + public string? AdminDetail { get; private set; } + public string? AdminPath { get; private set; } + public void OnGet() { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + + if (User.IsInRole("Admin")) + { + var feat = HttpContext.Features.Get(); + AdminPath = feat?.Path; + if (feat?.Error is { } ex) + AdminDetail = ex.GetType().FullName + ": " + ex.Message + + (ex.InnerException is { } ie ? $"\n ↳ {ie.GetType().Name}: {ie.Message}" : "") + + "\n\n" + ex.StackTrace; + } } }