Blog/Components/Pages/Error.razor 1.2 K · 39 lines · raw · history

1 @page "/Error"
2 @using System.Diagnostics
3 @using Microsoft.AspNetCore.Http
4
5 <PageTitle>Error</PageTitle>
6
7 <main>
8 <h1>Error.</h1>
9 <h2>An error occurred while processing your request.</h2>
10
11 @if (ShowRequestId)
12 {
13 <p>
14 <strong>Request ID:</strong> <code>@RequestId</code>
15 </p>
16 }
17
18 <h3>Development Mode</h3>
19 <p>
20 Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
21 </p>
22 <p>
23 <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
24 It can result in displaying sensitive information from exceptions to end users.
25 For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
26 and restarting the app.
27 </p>
28 </main>
29
30 @code{
31 [CascadingParameter] private HttpContext? HttpContext { get; set; }
32
33 private string? RequestId { get; set; }
34 private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
35
36 protected override void OnInitialized() =>
37 RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
38
39 }