Skip to content

Commit 6d10c2d

Browse files
authored
Add blazor server sample (#1699)
1 parent 15f3094 commit 6d10c2d

29 files changed

+1209
-0
lines changed

Sentry.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Testing.CrashableApp
153153
EndProject
154154
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.MacCatalyst", "samples\Sentry.Samples.MacCatalyst\Sentry.Samples.MacCatalyst.csproj", "{3506539B-983C-44FD-BD95-1931562E7919}"
155155
EndProject
156+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AspNetCore.Blazor.Server", "samples\Sentry.Samples.AspNetCore.Blazor.Server\Sentry.Samples.AspNetCore.Blazor.Server.csproj", "{70066C6C-0A18-4322-A02A-9A0DFE59C02B}"
157+
EndProject
156158
Global
157159
GlobalSection(SolutionConfigurationPlatforms) = preSolution
158160
Debug|Any CPU = Debug|Any CPU
@@ -362,6 +364,10 @@ Global
362364
{3506539B-983C-44FD-BD95-1931562E7919}.Release|Any CPU.ActiveCfg = Release|Any CPU
363365
{3506539B-983C-44FD-BD95-1931562E7919}.Release|Any CPU.Build.0 = Release|Any CPU
364366
{3506539B-983C-44FD-BD95-1931562E7919}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
367+
{70066C6C-0A18-4322-A02A-9A0DFE59C02B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
368+
{70066C6C-0A18-4322-A02A-9A0DFE59C02B}.Debug|Any CPU.Build.0 = Debug|Any CPU
369+
{70066C6C-0A18-4322-A02A-9A0DFE59C02B}.Release|Any CPU.ActiveCfg = Release|Any CPU
370+
{70066C6C-0A18-4322-A02A-9A0DFE59C02B}.Release|Any CPU.Build.0 = Release|Any CPU
365371
EndGlobalSection
366372
GlobalSection(SolutionProperties) = preSolution
367373
HideSolutionNode = FALSE
@@ -419,6 +425,7 @@ Global
419425
{C2876321-A612-4E66-AF33-D3928FA6366F} = {77454495-55EE-4B40-A089-71B9E8F82E89}
420426
{DA3CECBB-83BE-441A-852C-077809C48307} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
421427
{3506539B-983C-44FD-BD95-1931562E7919} = {77454495-55EE-4B40-A089-71B9E8F82E89}
428+
{70066C6C-0A18-4322-A02A-9A0DFE59C02B} = {77454495-55EE-4B40-A089-71B9E8F82E89}
422429
EndGlobalSection
423430
GlobalSection(ExtensibilityGlobals) = postSolution
424431
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page "/"
2+
3+
<PageTitle>Index</PageTitle>
4+
5+
<h1>Hello, world!</h1>
6+
7+
Welcome to your new app.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page "/thrower"
2+
@using Microsoft.Extensions.Logging
3+
@inject ILogger<Thrower> Logger
4+
5+
<h1>Throw Exception</h1>
6+
7+
<button class="btn btn-primary" @onclick="Throw">Throw</button>
8+
9+
@if (SentrySdk.LastEventId != SentryId.Empty)
10+
{
11+
<p>Event Id: @SentrySdk.LastEventId</p>
12+
}
13+
14+
@code {
15+
private void Throw()
16+
{
17+
Logger.LogInformation("Doing something ... ");
18+
Stuff.DoSomething();
19+
}
20+
21+
private static class Stuff
22+
{
23+
public static void DoSomething() => Thrower();
24+
private static void Thrower() => throw new ("The exception message");
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
@namespace Sentry.Samples.AspNetCore.Blazor.Server.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = "_Layout";
6+
}
7+
8+
<component type="typeof(App)" render-mode="ServerPrerendered" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@namespace Sentry.Samples.AspNetCore.Blazor.Server.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<base href="~/" />
11+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
12+
<link href="css/site.css" rel="stylesheet" />
13+
<link href="Sentry.Samples.AspNetCore.Blazor.Server.styles.css" rel="stylesheet" />
14+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
15+
</head>
16+
<body>
17+
@RenderBody()
18+
19+
<div id="blazor-error-ui">
20+
<environment include="Staging,Production">
21+
An error has occurred. This application may no longer respond until reloaded.
22+
</environment>
23+
<environment include="Development">
24+
An unhandled exception has occurred. See browser dev tools for details.
25+
</environment>
26+
<a href="" class="reload">Reload</a>
27+
<a class="dismiss">🗙</a>
28+
</div>
29+
30+
<script src="_framework/blazor.server.js"></script>
31+
</body>
32+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Capture blazor bootstrapping errors
2+
3+
var builder = WebApplication.CreateBuilder(args);
4+
5+
builder.Services.AddRazorPages();
6+
builder.Services.AddServerSideBlazor();
7+
builder.WebHost.UseSentry(options =>
8+
{
9+
options.Dsn = "https://[email protected]/5428537";
10+
options.Debug = true;
11+
});
12+
13+
var app = builder.Build();
14+
15+
// Enable Sentry performance monitoring
16+
app.UseSentryTracing();
17+
18+
app.UseHttpsRedirection();
19+
20+
app.UseStaticFiles();
21+
22+
app.UseRouting();
23+
24+
app.MapBlazorHub();
25+
app.MapFallbackToPage("/_Host");
26+
27+
app.Run();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57711",
7+
"sslPort": 44386
8+
}
9+
},
10+
"profiles": {
11+
"Sentry.Samples.AspNetCore.Blazor.Server": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "https://localhost:7263;http://localhost:5263",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Sentry.AspNetCore\Sentry.AspNetCore.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@inherits LayoutComponentBase
2+
3+
<PageTitle>Sentry.Samples.AspNetCore.Blazor.Server</PageTitle>
4+
5+
<div class="page">
6+
<div class="sidebar">
7+
<NavMenu />
8+
</div>
9+
10+
<main>
11+
<div class="top-row px-4">
12+
<a href="https://sentry.io/welcome/" target="_blank">Sentry</a>
13+
</div>
14+
15+
<article class="content px-4">
16+
@Body
17+
</article>
18+
</main>
19+
</div>

0 commit comments

Comments
 (0)