-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Blazor] Runtime APIs to support fingerprinting #56076
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
[API Review]
Current status is that we need to figure out a good name for the main public API. We can't review the other pieces properly until we understand that. |
[API Review]
|
It seems the <script type="module">
import * as lit from "https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js"
console.log(lit)
</script> |
@felixcicatt Can you please file a new issue? Feel free to tag this one if you believe it's related. |
Description
These set of APIs allow Blazor, MVC and Razor pages to map well-known URLs to content-specific (fingerprinted URLs).
Scenarios
Startup/Program APIs
The list of assets is defined on a per-endpoint basis. MVC and RazorPages opt-in to the feature via a call to
WithResourceCollection
following the call toMapRazorPages()
orMapControllers()
.This call adds a
ResourceAssetCollection
to the Metadata collection of the endpoints, which contains the mapping between human-readable URLs and content-specific URLs.From there, other components can retrieve the mapping from endpoint metadata.
app.MapStaticAssets(); app.MapRazorPages() + .WithResourceCollection();
Since we can have calls to map different manifests,
WithResourceCollection
takes a parameter to provide the Id for the matchingMatchStaticAssets
.app.MapStaticAssets("WebassemblyApp1.Client"); app.MapStaticAssets("WebassemblyApp2.Client"); app.MapRazorPages() + .WithResourceCollection("WebassemblyApp1.Client");
Consuming the mapped assets
The assets are consumed indirectly from MVC and Razor Pages via existing
Script
,Image
,Link
, andUrl
tag helpers.In Blazor, the assets are consumed via the
Assets
property inComponentBase
which exposes an indexer to resolve the fingerprinted url for a given asset.This in the future will be cleaner with a compiler feature similar to the Url tag helper in MVC that transforms "~/app.css" into the above code inside the href attribute.
In addition to this, there are two built-in components to generate an importmap for scripts. See here for details.
TL;DR: Creates a mapping for calls to
import
and scripttype="module"
that optionally includes integrity information. A sample:There is an ImportMap blazor component
and in MVC we extended the script tag helper to support it
Layering
I included this section to explain the reasons for some of the APIs below.
Two important things:
With this in mind, information for the assets is exposed differently from StaticAssets and Components
The Component endpoints assembly is the one responsible for mapping the
StaticAssetDescriptor
s into theResourceAssetCollection
so that Blazor and MVC can consume them.Microsoft.AspNetCore.Components.dll
Microsoft.AspNetCore.Components.Endpoints
Assembly Microsoft.AspNetCore.WebUtilities
namespace Microsoft.AspNetCore.WebUtilities; public class WebEncoders { + Base64UrlEncode(System.ReadOnlySpan<byte> input, System.Span<char> output) }
Assembly Microsoft.AspNetCore.Mvc.RazorPages
Microsoft.AspNetCore.Mvc.ViewFeatures
Assembly Microsoft.AspNetCore.Mvc.TagHelpers.dll
Assembly Microsoft.AspNetCore.StaticAssets.dll
The text was updated successfully, but these errors were encountered: