Skip to content

Commit ada67fc

Browse files
committed
Merge branch 'main' into 12Release
2 parents 58ff44e + 1f4826a commit ada67fc

File tree

146 files changed

+87093
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+87093
-28
lines changed

Microsoft.AspNetCore.SystemWebAdapters.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcCoreApp", "samples\Remot
6565
EndProject
6666
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreApp", "samples\CoreApp\CoreApp.csproj", "{431651D7-D40A-403E-813C-496A1414AA22}"
6767
EndProject
68+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebFormsToBlazor", "WebFormsToBlazor", "{3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}"
69+
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebFormsFramework", "samples\WebFormsToBlazor\WebFormsFramework\WebFormsFramework.csproj", "{0993BA4C-218B-43DD-A8A0-997B05808A08}"
71+
EndProject
72+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorCore", "samples\WebFormsToBlazor\BlazorCore\BlazorCore.csproj", "{23094126-C05C-4172-A01F-998780976709}"
6873
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}"
6974
EndProject
7075
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModulesLibrary", "samples\Modules\ModulesLibrary\ModulesLibrary.csproj", "{5597A485-4D9B-4CE6-A489-DEBE9338450F}"
@@ -155,6 +160,14 @@ Global
155160
{431651D7-D40A-403E-813C-496A1414AA22}.Debug|Any CPU.Build.0 = Debug|Any CPU
156161
{431651D7-D40A-403E-813C-496A1414AA22}.Release|Any CPU.ActiveCfg = Release|Any CPU
157162
{431651D7-D40A-403E-813C-496A1414AA22}.Release|Any CPU.Build.0 = Release|Any CPU
163+
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
164+
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Debug|Any CPU.Build.0 = Debug|Any CPU
165+
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Release|Any CPU.ActiveCfg = Release|Any CPU
166+
{0993BA4C-218B-43DD-A8A0-997B05808A08}.Release|Any CPU.Build.0 = Release|Any CPU
167+
{23094126-C05C-4172-A01F-998780976709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
168+
{23094126-C05C-4172-A01F-998780976709}.Debug|Any CPU.Build.0 = Debug|Any CPU
169+
{23094126-C05C-4172-A01F-998780976709}.Release|Any CPU.ActiveCfg = Release|Any CPU
170+
{23094126-C05C-4172-A01F-998780976709}.Release|Any CPU.Build.0 = Release|Any CPU
158171
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159172
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Debug|Any CPU.Build.0 = Debug|Any CPU
160173
{5597A485-4D9B-4CE6-A489-DEBE9338450F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -196,6 +209,9 @@ Global
196209
{174A36F1-27ED-43FC-A3A1-00DA58C4E30C} = {9C8EBDB5-FA17-4C9C-8946-04692AC752CE}
197210
{2BF8EE74-1AB3-4DB8-ADDE-27A35981CA04} = {9C8EBDB5-FA17-4C9C-8946-04692AC752CE}
198211
{431651D7-D40A-403E-813C-496A1414AA22} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
212+
{3A71E8B4-7E40-4326-B5FC-0CFA30A388D1} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
213+
{0993BA4C-218B-43DD-A8A0-997B05808A08} = {3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}
214+
{23094126-C05C-4172-A01F-998780976709} = {3A71E8B4-7E40-4326-B5FC-0CFA30A388D1}
199215
{4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C} = {95915611-30BF-4AFF-AE41-5CDC6F57DCF7}
200216
{5597A485-4D9B-4CE6-A489-DEBE9338450F} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
201217
{B262AD69-11F0-4AE0-949A-AEAA2300C061} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" Version="7.0.3" />
11+
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.SystemWebAdapters.CoreServices\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Reflection;
2+
using Microsoft.AspNetCore.Components;
3+
4+
namespace BlazorCore;
5+
6+
public static class BlazorEndpointRouteBuilderExtensions
7+
{
8+
public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page)
9+
{
10+
var assembly = Assembly.GetEntryAssembly();
11+
if (assembly is null)
12+
{
13+
throw new InvalidOperationException("No entry assembly available.");
14+
}
15+
return endpoints.MapBlazorPages(page, assembly);
16+
}
17+
18+
public static IEndpointConventionBuilder MapBlazorPages(this IEndpointRouteBuilder endpoints, string page, params Assembly[] assemblies)
19+
{
20+
ArgumentNullException.ThrowIfNull(assemblies);
21+
var builder = new BlazorEndpointConventionBuilder();
22+
foreach (var route in GetRoutes(assemblies))
23+
{
24+
var conventionBuilder = endpoints.MapFallbackToPage(route, page);
25+
conventionBuilder.Add(b =>
26+
{
27+
// By default this will be 'Fallback {route}', but this will help identify it is explicitly registered
28+
b.DisplayName = $"Blazor {route}";
29+
// {page} will, by default, have Order = 0; this will ensure the order is not the same
30+
((RouteEndpointBuilder)b).Order = -1;
31+
});
32+
builder.Add(conventionBuilder);
33+
}
34+
return builder;
35+
}
36+
37+
private static IEnumerable<string> GetRoutes(Assembly[] assemblies)
38+
{
39+
foreach (var assembly in assemblies)
40+
{
41+
foreach (var type in assembly.GetTypes())
42+
{
43+
if (typeof(IComponent).IsAssignableFrom(type))
44+
{
45+
foreach (var attribute in type.GetCustomAttributes(typeof(RouteAttribute)))
46+
{
47+
if (attribute is RouteAttribute { Template: { } route })
48+
{
49+
yield return route;
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
57+
private sealed class BlazorEndpointConventionBuilder : IEndpointConventionBuilder
58+
{
59+
private readonly List<IEndpointConventionBuilder> _builders = new();
60+
public void Add(IEndpointConventionBuilder builder)
61+
{
62+
_builders.Add(builder);
63+
}
64+
void IEndpointConventionBuilder.Add(Action<EndpointBuilder> convention)
65+
{
66+
foreach (var builder in _builders)
67+
{
68+
builder.Add(convention);
69+
}
70+
}
71+
#if NET7_0_OR_GREATER
72+
void IEndpointConventionBuilder.Finally(Action<EndpointBuilder> finalConvention)
73+
{
74+
foreach (var builder in _builders)
75+
{
76+
builder.Finally(finalConvention);
77+
}
78+
}
79+
#endif
80+
}
81+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace BlazorCore.Data
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace BlazorCore.Data
2+
{
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h3>HelloWorld from ASP.NET Core</h3>
2+
3+
Current path: @Path
4+
5+
@code {
6+
[Parameter]
7+
public string Path { get; set; } = "no-route";
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model BlazorCore.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace BlazorCore.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)