Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions AspNetCore.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,6 @@
<Project Path="src/Servers/Kestrel/perf/Microbenchmarks/Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks.csproj" />
</Folder>
<Folder Name="/src/Servers/Kestrel/samples/">
<Project Path="src/Servers/Kestrel/samples/DirectTlsTransportApp/DirectTlsTransportApp.csproj" />
<Project Path="src/Servers/Kestrel/samples/http2cat/http2cat.csproj" />
<Project Path="src/Servers/Kestrel/samples/Http2SampleApp/Http2SampleApp.csproj" />
<Project Path="src/Servers/Kestrel/samples/Http3SampleApp/Http3SampleApp.csproj" />
Expand All @@ -1082,10 +1081,6 @@
<Folder Name="/src/Servers/Kestrel/tools/">
<Project Path="src/Servers/Kestrel/tools/CodeGenerator/CodeGenerator.csproj" />
</Folder>
<Folder Name="/src/Servers/Kestrel/Transport.DirectTls/">
<Project Path="src/Servers/Kestrel/Transport.DirectTls/src/Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls.csproj" />
<Project Path="src/Servers/Kestrel/Transport.DirectTls/test/Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls.Tests.csproj" />
</Folder>
<Folder Name="/src/Servers/Kestrel/Transport.Quic/">
<Project Path="src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj" />
<Project Path="src/Servers/Kestrel/Transport.Quic/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.csproj" />
Expand Down
1 change: 0 additions & 1 deletion eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.IIS" ProjectPath="$(RepoRoot)src\Servers\IIS\IIS\src\Microsoft.AspNetCore.Server.IIS.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Core" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Core\src\Microsoft.AspNetCore.Server.Kestrel.Core.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Kestrel\src\Microsoft.AspNetCore.Server.Kestrel.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.DirectTls\src\Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.NamedPipes\src\Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Quic" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Quic\src\Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Sockets\src\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj" />
Expand Down
1 change: 0 additions & 1 deletion eng/ShippingAssemblies.props
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Identity.Specification.Tests" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Identity.UI" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Authentication.Certificate" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Authentication.DeviceBoundSessions" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.Authentication.Facebook" />
Expand Down
1 change: 0 additions & 1 deletion eng/TrimmableProjects.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<TrimmableProject Include="Microsoft.AspNetCore.Server.IIS" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Core" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.DirectTls" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Quic" />
<TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" />
Expand Down
10 changes: 2 additions & 8 deletions src/Components/Components/src/Routing/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,7 @@ internal void RenderComponentByRoute(RenderTreeBuilder builder, string route)
$"Ensure the route matches a component with a [Route] attribute.");
}

builder.OpenComponent<RouteView>(0);
builder.AddAttribute(1, nameof(RouteView.RouteData),
new RouteData(componentType, new Dictionary<string, object>()));
builder.CloseComponent();
Found(new RouteData(componentType, new Dictionary<string, object>()))(builder);
}

[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Expand All @@ -446,10 +443,7 @@ private void RenderNotFound()
{
if (NotFoundPage != null)
{
builder.OpenComponent<RouteView>(0);
builder.AddAttribute(1, nameof(RouteView.RouteData),
new RouteData(NotFoundPage, _emptyParametersDictionary));
builder.CloseComponent();
Found(new RouteData(NotFoundPage, _emptyParametersDictionary))(builder);
}
#pragma warning disable CS0618 // Type or member is obsolete
else if (NotFound != null)
Expand Down
48 changes: 19 additions & 29 deletions src/Components/Components/test/Routing/RouterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,7 @@ await testRenderer.Dispatcher.InvokeAsync(() =>
// Assert
var lastBatch = testRenderer.Batches.Last();
var renderedFrame = lastBatch.ReferenceFrames.First();
Assert.Equal(RenderTreeFrameType.Component, renderedFrame.FrameType);
Assert.Equal(typeof(RouteView), renderedFrame.ComponentType);

// Verify that the RouteData contains the NotFoundTestComponent
var routeViewFrame = lastBatch.ReferenceFrames.Skip(1).First();
Assert.Equal(RenderTreeFrameType.Attribute, routeViewFrame.FrameType);
var routeData = (RouteData)routeViewFrame.AttributeValue;
Assert.Equal(typeof(NotFoundTestComponent), routeData.PageType);
Assert.Equal($"Rendering route matching {typeof(NotFoundTestComponent)}", renderedFrame.TextContent);
}

[Fact]
Expand Down Expand Up @@ -389,16 +382,12 @@ await testRenderer.Dispatcher.InvokeAsync(() =>
await testRenderer.Dispatcher.InvokeAsync(() => testNavManager.TriggerNotFound());

// Assert
var lastBatch = testRenderer.Batches.Last();
var renderedFrame = lastBatch.ReferenceFrames.First();
Assert.Equal(RenderTreeFrameType.Component, renderedFrame.FrameType);
Assert.Equal(typeof(RouteView), renderedFrame.ComponentType);

// Verify that the RouteData contains the correct component type
var routeViewFrame = lastBatch.ReferenceFrames.Skip(1).First();
Assert.Equal(RenderTreeFrameType.Attribute, routeViewFrame.FrameType);
var routeData = (RouteData)routeViewFrame.AttributeValue;
Assert.Equal(typeof(JanComponent), routeData.PageType);
var textFrame = testRenderer.Batches
.SelectMany(b => b.ReferenceFrames)
.FirstOrDefault(f => f.FrameType == RenderTreeFrameType.Text
&& f.TextContent == $"Rendering route matching {typeof(JanComponent)}");
Assert.True(textFrame.FrameType == RenderTreeFrameType.Text,
"Expected the Found fragment's rendered text for JanComponent to appear in a batch.");
}

[Fact]
Expand Down Expand Up @@ -440,17 +429,18 @@ await testRenderer.Dispatcher.InvokeAsync(() =>
// trigger the NavigationManager's OnNotFound event
await testRenderer.Dispatcher.InvokeAsync(() => testNavManager.TriggerNotFound());

// The Router should have rendered using RenderComponentByRoute (args.Path) instead of NotFoundPage
var lastBatch = testRenderer.Batches.Last();
var renderedFrame = lastBatch.ReferenceFrames.First();
Assert.Equal(RenderTreeFrameType.Component, renderedFrame.FrameType);
Assert.Equal(typeof(RouteView), renderedFrame.ComponentType);

// Verify that the RouteData contains the JanComponent (from args.Path), not NotFoundTestComponent
var routeViewFrame = lastBatch.ReferenceFrames.Skip(1).First();
Assert.Equal(RenderTreeFrameType.Attribute, routeViewFrame.FrameType);
var routeData = (RouteData)routeViewFrame.AttributeValue;
Assert.Equal(typeof(JanComponent), routeData.PageType);
// The Router should have rendered using RenderComponentByRoute (args.Path) instead of NotFoundPage,
// routed through the user-supplied <Found> fragment.
var textFrame = testRenderer.Batches
.SelectMany(b => b.ReferenceFrames)
.FirstOrDefault(f => f.FrameType == RenderTreeFrameType.Text
&& f.TextContent == $"Rendering route matching {typeof(JanComponent)}");
Assert.True(textFrame.FrameType == RenderTreeFrameType.Text,
"Expected the args.Path component (JanComponent) to be rendered through Found, not NotFoundTestComponent.");
Assert.DoesNotContain(testRenderer.Batches
.SelectMany(b => b.ReferenceFrames),
f => f.FrameType == RenderTreeFrameType.Text
&& f.TextContent == $"Rendering route matching {typeof(NotFoundTestComponent)}");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,27 @@ public void NotFoundSetOnFormSubmit_ResponseStarted_CustomRouter_SSR()
AssertUrlNotChanged(testUrl);
}

[Fact]
public void NotFoundSetOnInitialization_AppSetsEventArgsPathToAuthorizedRoute_AnonymousUser_RendersNotAuthorizedContent()
{
string testUrl = $"{ServerPathBase}/set-not-found-ssr?appSetsEventArgsPath=true&useAuthorizedNotFoundPage=true";
Navigate(testUrl);

Browser.Equal("Not authorized to view this page.", () => Browser.Exists(By.Id("not-authorized-content")).Text);
Browser.DoesNotExist(By.Id("protected-not-found-content"));
AssertUrlNotChanged(testUrl);
}

[Fact]
public void NotFoundSetOnInitialization_AuthorizedNotFoundPage_AnonymousUser_RendersNotAuthorizedContent()
{
string testUrl = $"{ServerPathBase}/set-not-found-ssr?useAuthorizedNotFoundPage=true";
Navigate(testUrl);
Browser.Equal("Not authorized to view this page.", () => Browser.Exists(By.Id("not-authorized-content")).Text);
Browser.DoesNotExist(By.Id("protected-not-found-content"));
AssertUrlNotChanged(testUrl);
}

[Fact]
public void StatusCodePagesWithReExecution()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void ConfigureServices(IServiceCollection services)
}

services.AddHttpContextAccessor();
services.AddAuthorizationCore();
services.AddCascadingAuthenticationState();

if (Configuration.GetValue<bool>("UseSession"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using TestContentPackage.NotFound
@using Components.TestServer.RazorComponents
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using System.Threading.Tasks
Expand All @@ -12,6 +13,10 @@
[Parameter]
[SupplyParameterFromQuery(Name = "useCustomNotFoundPage")]
public string? UseCustomNotFoundPage { get; set; }

[Parameter]
[SupplyParameterFromQuery(Name = "useAuthorizedNotFoundPage")]
public string? UseAuthorizedNotFoundPage { get; set; }

[Parameter]
[SupplyParameterFromQuery(Name = "useCustomRouter")]
Expand Down Expand Up @@ -58,7 +63,9 @@

private void OnNotFoundEvent(object sender, NotFoundEventArgs e)
{
var type = typeof(CustomNotFoundPage);
var type = string.Equals(UseAuthorizedNotFoundPage, "true", StringComparison.OrdinalIgnoreCase)
? typeof(AuthorizedNotFoundPage)
: typeof(CustomNotFoundPage);
var routeAttributes = type.GetCustomAttributes(typeof(RouteAttribute), inherit: true);
if (routeAttributes.Length == 0)
{
Expand All @@ -75,7 +82,11 @@

protected override void OnParametersSet()
{
if (string.Equals(UseCustomNotFoundPage, "true", StringComparison.OrdinalIgnoreCase))
if (string.Equals(UseAuthorizedNotFoundPage, "true", StringComparison.OrdinalIgnoreCase))
{
NotFoundPageType = typeof(AuthorizedNotFoundPage);
}
else if (string.Equals(UseCustomNotFoundPage, "true", StringComparison.OrdinalIgnoreCase))
{
NotFoundPageType = typeof(CustomNotFoundPage);
}
Expand Down Expand Up @@ -135,6 +146,20 @@
</Found>
</CustomRouter>
}
else if (string.Equals(UseAuthorizedNotFoundPage, "true", StringComparison.OrdinalIgnoreCase))
{
<Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="new[] { typeof(TestContentPackage.NotFound.NotFoundPage).Assembly }" NotFoundPage="NotFoundPageType">

<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData">
<NotAuthorized>
<p id="not-authorized-content">Not authorized to view this page.</p>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="[data-focus-on-navigate]" />
</Found>
</Router>
}
else
{
@if (NotFoundPageType is not null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@page "/render-authorized-not-found-page"
@layout NotFoundLayout
@attribute [Microsoft.AspNetCore.Authorization.Authorize(Roles = "Admin")]

<h3 id="test-info">Welcome On Authorized Not Found Page</h3>
<p id="protected-not-found-content">This page is protected and should not be rendered for anonymous users.</p>
61 changes: 0 additions & 61 deletions src/Servers/Kestrel/Core/src/DirectTlsEndpoint.cs

This file was deleted.

Loading
Loading