Skip to content

Using PageLoader for multiple endpoints can cause the loss of endpoint metadata #33354

@jeffpapp

Description

@jeffpapp

Describe the bug

I'm using PageLoader per @davidfowl's recommendation to get the full metadata for multiple endpoints on a single razor page. I've noticed that after I've loaded an endpoint via PageLoader that hasn't been visited via an HTTP request, then there is metadata missing that would normally be there without using PageLoader.

For example, if I call endpoints.MapRazorPages().WithMetadata("Some Metadata") and then inspect the endpoint in middleware during a normal request the custom metadata exists on the endpoint. But if I load the endpoint with PageLoader first before doing an actual HTTP request then the custom data does not exist on the endpoint.

During a normal request PageLoaderMatcherPolicy specifically calls DefaultPageLoader.LoadAsync() with the original endpoint metadata and then enriches it with the compiled metadata and then caches the value. Unfortunately, the PageLoader.LoadAsync(PageActionDescriptor actionDescriptor, EndpointMetadataCollection endpointMetadata) method is marked internal so I can't pass along the original endpoint metadata so the endpoint is cached with missing metadata. See my linked GitHub repo below for an example of this.

Is there a better way for me to get all the endpoints in my app with their full metadata other than calling PageLoader? Or should I be calling PageLoader differently?

To Reproduce

See an example at https://github.com/jeffpapp/PageLoaderSample/tree/main/PageLoaderSample

If you run the sample project and follow the Go to Next Page links you will see that the third page is missing the custom metadata on it's endpoint because the second page called PageLoader which overrode the default behavior of PageLoaderMatcherPolicy and cached an endpoint without all the metadata you'd expect.

Further technical details

  • ASP.NET Core version: 5.0.6
  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.6
  Commit:  478b2f8c0e

.NET SDKs installed:
  3.1.402 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: VS 2019 16.9.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesinvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions