Skip to content

Conversation

guardrex
Copy link
Collaborator

@guardrex guardrex commented Aug 20, 2025

Fixes #35810
Fixes #35833

After Javier technical review, I'll ping Wade and Tom.

Notes

  • Let's combine articles. IMO, it's kind'a scatter-🧠 to have two static files articles.
  • 'Look ma! No broken links!' 😆 Let's drop the horribad INCLUDES versioning for two great outcomes ...
    • Links aren't broken in prior-version content.
    • The team and community are prevented from only updating the latest version of the article. That will still be a problem if we ever go to group-topic versioning (aka "Version-by-file"), but I don't think that's ever going to happen. If we're on the current versioning model forever, this approach stops the poor practice of only making bug fixes to the latest release content (i.e., INCLUDES files are routinely ignored for bug and enhancement updates).
  • Let's move the samples into the dotnet/AspNetCore.Docs.Samples repo. The sample apps were placed in that repo on Add static files sample apps AspNetCore.Docs.Samples#282. I'll delete them from this repo on this PR after reviews to avoid cluttering the diff.
  • We're still running with the separate Blazor Static Files article with Blazor-focused scenarios. Dan, I can move that content (or selected bits of it) into this article if you want. 👂

Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/fundamentals/environments.md aspnetcore/blazor/fundamentals/environments
aspnetcore/blazor/fundamentals/static-files.md aspnetcore/blazor/fundamentals/static-files
aspnetcore/fundamentals/static-files.md aspnetcore/fundamentals/static-files
aspnetcore/migration/50-to-60-samples.md aspnetcore/migration/50-to-60-samples
aspnetcore/migration/70-80.md aspnetcore/migration/70-80
aspnetcore/toc.yml aspnetcore/toc

@guardrex guardrex self-assigned this Aug 20, 2025
@guardrex guardrex marked this pull request as ready for review August 20, 2025 15:54
@guardrex guardrex requested a review from Copilot August 20, 2025 16:08
Copilot

This comment was marked as outdated.

@guardrex guardrex requested a review from danroth27 August 20, 2025 16:27
@guardrex guardrex force-pushed the guardrex/static-files branch from 9ee972a to a2b8c81 Compare August 28, 2025 17:47

:::moniker range=">= aspnetcore-6.0"

*The guidance in this section applies to Razor Pages and MVC apps. For guidance that applies to Blazor Web Apps, see <xref:blazor/fundamentals/static-files#serve-files-from-multiple-locations>.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the guidance the same? Can we remove this duplication?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I meant about deltas. It wasn't the same IIRC, but I'll have to look. I'll check and get back to you ... probably Tuesday morning.

Copy link
Collaborator Author

@guardrex guardrex Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed my last response. I was incorrect about what happened.

A dev had a problem getting our main doc set guidance with the composite file provider to work in a BWA with two physical file providers (which BTW works for Blazor Server, just not BWAs) ...

#32891

I asked the dev to open a PU issue to see what we needed to do for BWAs ...

#32895

However, the issue was transferred to the docs repo without comment. I closed the transferred issue to work from the original docs issue (32891).

I presumed that what the dev did to solve the problem was a valid approach, so that's what's in the section. Instead of using two physical file providers in a composite file provider, the Blazor content pitches passing app.Environment.WebRootFileProvider as the primary provider ...

var secondaryProvider = new PhysicalFileProvider(
    Path.Combine(builder.Environment.ContentRootPath, "AdditionalStaticAssets"));
app.Environment.WebRootFileProvider = new CompositeFileProvider(
    app.Environment.WebRootFileProvider, secondaryProvider);

So, we still don't have an "official" Javier ruling 👨‍⚖️😄 on this delta (two physical providers in a composite doesn't work in a BWA). I'll leave the current coverage as it is for now, and then we can see on technical review what to do about BWA coverage for serving files from multiple locations.

[Note in passing that what I said in my stricken comment about the main doc set's section partially focusing the Image Tag Helper in this scenario is true. When I added the Blazor article coverage, I stripped that language out, so the Blazor article section may or may not be the right pitch on how to address the multiple locations scenario for BWAs, but it is better tailored to BWAs without the Tag Helper remarks. That's something that I'd try to address in the main doc set if we shed the Blazor article section after hearing back from Javier.]

Here are the two live sections for further analysis on their deltas to see if we should try combining them in the main doc set article ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'm going to assume the differences in this content for handling static files from multiple locations in Blazor Web Apps is correct then unless @javiercn states otherwise.

@guardrex

This comment was marked as outdated.

guardrex and others added 3 commits September 2, 2025 08:42
Co-authored-by: Daniel Roth <daroth@microsoft.com>
@guardrex

This comment was marked as outdated.


By default, static files are stored within the project's [web root](xref:fundamentals/index#web-root) directory. The default directory is `{CONTENT ROOT}/wwwroot`, where the `{CONTENT ROOT}` placeholder is the app's [content root](xref:fundamentals/index#content-root). Only files in the wwwroot folder will be addressable, so you don't need to worry about the rest of your code.

Only files with specific file extensions mapped to supported media types are treated as static web assets.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiercn Is there more we should say about the default media type mapping for static web assets and how it can be configured?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I included a section about that in my original technical description. it should be covered here if it's not covered later in the document. At leas a note/link here to where it can be configured later.

Copy link
Collaborator Author

@guardrex guardrex Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only going by what's here, so I need to understand where the original technical description is in order to add content ... or the content, possibly as just notes, has to be provided to me.

Copy link
Member

@danroth27 danroth27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall structure looks good to me. There is a fair bit of technical details that we'll need @javiercn to review.

Currently, I'm wondering why any fundamental coverage (or host/deploy ... or security) is covered in the Blazor node, given Blazor's preeminent position.

Yup, I agree we should look at what Blazor fundamentals content should really be in the top-level fundamentals docs. Let's just be careful not to overwhelm the top-level ASP.NET Core fundamentals docs with too many Blazor-specific details. We need the fundamental concepts of ASP.NET Core to be simple and straightforward.

I think it should be "Static File Middleware," not "Files" (plural). The API isn't plural.

Sounds good to me 👍

Co-authored-by: Daniel Roth <daroth@microsoft.com>
@guardrex guardrex requested a review from javiercn September 16, 2025 12:02
@guardrex
Copy link
Collaborator Author

This PR is ready for @javiercn's technical review.

`DisableBuildCompression` | Disables compression during build.
`CompressDiscoveredAssetsDuringBuild` | Compresses discovered assets during build.
`BrotliCompressionLevel` | Compression level for the Brotli algorithm.
`LinkAlternativeRepresentationsToOriginalResource` | How to link compressed assets to original resources.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this property, I missed it when I created the list, it should not be here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally be on its own section as Customizing compression options and providing examples.


Item group | Description | Metadata
--- | ---
`StaticWebAssetContentTypeMapping` | Maps file patterns to content types and cache headers for endpoints. | Pattern, Cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be covered under a section about "adding new content type mappings at build time"

Copy link
Collaborator Author

@guardrex guardrex Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I placed everything that you provided in dotnet/aspnetcore#63292. I need content or a link to additional information if I'm going to write it up (and note that @danroth27 asked me not to write up new features; leave it to the PU he instructed).

Also, I placed this section on MSBuild properties without versioning any of them. They don't all go back to 3.1, so I leave it to you guys to decide if versioning is something you want to get into the weeds with. If several came in at various times (and because I can't version individual rows of tables), this could get messy fast.

If you want to version without markdown versioning, then a table column can indicate the release that the property appeared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guardrex @javiercn I've opened dotnet/aspnetcore#63698 to track providing the requested content. Let's merge this PR as is and add the content type mapping section separately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ... I have one more pass to get the sample app out of here. It's in the samples repo now. I didn't do it yet because I didn't want to clutter the diff. I'll take care of it by EOD.

Copy link
Member

@javiercn javiercn Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<ItemGroup>
    <StaticWebAssetContentTypeMapping Include="image/bmp" Cache="<<Cache-Header-To-Use-For-Non-Fingerprinted-Endpoints>>" Pattern="*.bmp" />
</ItemGroup>

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, otherwise looks good.

@guardrex
Copy link
Collaborator Author

guardrex commented Sep 16, 2025

@danroth27 ... Ok, those two are done, and the samples are now only in the samples repo, not here.

I think we're good 👍. I'll see it live tomorrow morning and look for any lingering 😈.

@guardrex guardrex merged commit 94a6e13 into main Sep 16, 2025
3 checks passed
@guardrex guardrex deleted the guardrex/static-files branch September 16, 2025 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[static-files] Missing information or sample code content Static assets article(s) updates
4 participants