oliverbooth.dev/OliverBooth/Pages/Error.cshtml.cs

29 lines
771 B
C#
Raw Permalink Normal View History

2023-05-26 19:05:44 +01:00
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
2023-08-04 12:57:35 +01:00
namespace OliverBooth.Pages;
2023-05-26 19:05:44 +01:00
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
2023-09-25 20:06:05 +01:00
public int HttpStatusCode { get; private set; }
2023-09-25 20:06:05 +01:00
public IActionResult OnGet(int? code = null)
2023-05-26 19:05:44 +01:00
{
2023-09-25 20:06:05 +01:00
HttpStatusCode = code ?? HttpContext.Response.StatusCode;
if (HttpStatusCode == 200)
{
2023-09-25 20:06:05 +01:00
return RedirectToPage("/Index");
}
2023-09-25 20:06:05 +01:00
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return Page();
2023-05-26 19:05:44 +01:00
}
}