diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b5cbb7148..9bc07e9c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - GetFromRuntimeInformation() in try-catch ([#1554](https://github.com/getsentry/sentry-dotnet/pull/1554)) - Make `Contexts` properties more thread-safe ([#1571](https://github.com/getsentry/sentry-dotnet/pull/1571)) - Fix `PlatformNotSupportedException` exception on `net6.0-maccatalyst` targets ([#1567](https://github.com/getsentry/sentry-dotnet/pull/1567)) +- In ASP.Net Core, make sure that `SentrySdk.LastEventId` is accessible from exception handler pages ([#1573](https://github.com/getsentry/sentry-dotnet/pull/1573)) ## 3.15.0 diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs b/samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs index 25e5875a79..d8af5a1775 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Controllers/HomeController.cs @@ -89,11 +89,16 @@ public IActionResult Contact( var id = sentry.CaptureException(e); - ViewData["Message"] = "An exception was caught and sent to Sentry! Event id: " + id; + ViewData["Message"] = "An exception was caught and sent to Sentry! Event ID: " + id; } return View(); } + public IActionResult Test() + { + throw new Exception("Test exception thrown in controller!"); + } + public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Properties/launchSettings.json b/samples/Sentry.Samples.AspNetCore.Mvc/Properties/launchSettings.json index cf4d99746c..7199004af8 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Properties/launchSettings.json +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Properties/launchSettings.json @@ -19,9 +19,9 @@ "commandName": "Project", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Production" }, "applicationUrl": "http://localhost:5001" } } -} \ No newline at end of file +} diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Contact.cshtml b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Contact.cshtml index a11a1867cf..a3b5fad6a5 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Contact.cshtml +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Contact.cshtml @@ -4,6 +4,9 @@

@ViewData["Title"]

@ViewData["Message"]

+

Sentry Event ID: @SentrySdk.LastEventId

+ +
One Microsoft Way
Redmond, WA 98052-6399
diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Test.cshtml b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Test.cshtml new file mode 100644 index 0000000000..d6071095da --- /dev/null +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Home/Test.cshtml @@ -0,0 +1,10 @@ +@using Samples.AspNetCore.Mvc +@{ + ViewData["Title"] = "Test"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Use this area to provide additional information.

+ + diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/Error.cshtml b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/Error.cshtml index cc94cb1783..b4f1f5a2ab 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/Error.cshtml +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/Error.cshtml @@ -1,4 +1,8 @@ -@model Samples.AspNetCore.Mvc.Models.ErrorViewModel +@using Sentry +@using Sentry.AspNetCore +@inject Microsoft.Extensions.Options.IOptions SentryOptions + +@model Samples.AspNetCore.Mvc.Models.ErrorViewModel @{ ViewData["Title"] = "Error"; } @@ -9,14 +13,21 @@ @if (Model.ShowRequestId) {

- Request ID: @Model.RequestId + Request ID: @Model.RequestId
+ Sentry Event ID: @SentrySdk.LastEventId

} - -

Development Mode

-

- Swapping to Development environment will display more detailed information about the error that occurred. -

-

- Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. -

+@if (SentrySdk.LastEventId != SentryId.Empty) +{ + + +} diff --git a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/_Layout.cshtml b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/_Layout.cshtml index 6a3f4bd654..ec035e4dcd 100644 --- a/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/_Layout.cshtml +++ b/samples/Sentry.Samples.AspNetCore.Mvc/Views/Shared/_Layout.cshtml @@ -17,7 +17,7 @@ -