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

29 lines
771 B
C#
Raw Permalink Normal View History

2023-05-26 18:05:44 +00:00
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
2023-08-04 11:57:35 +00:00
namespace OliverBooth.Pages;
2023-05-26 18:05:44 +00: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 19:06:05 +00:00
public int HttpStatusCode { get; private set; }
2023-09-25 19:06:05 +00:00
public IActionResult OnGet(int? code = null)
2023-05-26 18:05:44 +00:00
{
2023-09-25 19:06:05 +00:00
HttpStatusCode = code ?? HttpContext.Response.StatusCode;
if (HttpStatusCode == 200)
{
2023-09-25 19:06:05 +00:00
return RedirectToPage("/Index");
}
2023-09-25 19:06:05 +00:00
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return Page();
2023-05-26 18:05:44 +00:00
}
}