52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace maintenance.Pages.Errors;
|
|
|
|
public sealed class IndexModel : PageModel
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public IndexModel(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
[FromQuery(Name = "template")]
|
|
public string? TemplateName { get; set; }
|
|
|
|
[FromQuery(Name = "stub")]
|
|
public string? Stub { get; set; }
|
|
|
|
public IActionResult OnGet()
|
|
{
|
|
var effectiveTemplate = string.IsNullOrWhiteSpace(TemplateName)
|
|
? (_configuration["ErrorPages:DefaultTemplate"] ?? "unavailable")
|
|
: TemplateName;
|
|
|
|
if (!string.IsNullOrWhiteSpace(Stub))
|
|
{
|
|
var encodedStub = Uri.EscapeDataString(Stub.Trim());
|
|
var targetKind = effectiveTemplate.Equals("generic", StringComparison.OrdinalIgnoreCase) ||
|
|
effectiveTemplate.Equals("error", StringComparison.OrdinalIgnoreCase)
|
|
? "error"
|
|
: "maintenance";
|
|
return Redirect($"/{targetKind}?stub={encodedStub}");
|
|
}
|
|
|
|
if (effectiveTemplate.Equals("generic", StringComparison.OrdinalIgnoreCase) ||
|
|
effectiveTemplate.Equals("error", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return Redirect("/error");
|
|
}
|
|
|
|
if (effectiveTemplate.Equals("unavailable", StringComparison.OrdinalIgnoreCase) ||
|
|
effectiveTemplate.Equals("maintenance", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return Redirect("/maintenance");
|
|
}
|
|
|
|
return Redirect($"/maintenance?page={Uri.EscapeDataString(effectiveTemplate)}");
|
|
}
|
|
}
|