liveBook · Manning

Asp-href-include

As explained in Pro ASP.NET Core 7, Tenth Edition

The asp-href-include attribute specifies a globbing pattern for stylesheet files to include.

Use asp-href-include on a link element to select stylesheet files with a globbing pattern. Pair it with asp-href-exclude when a directory contains unwanted variants. section 26.4.2

Select one Bootstrap stylesheet

In Views/Shared/_SimpleLayout.cshtml, set asp-href-include="/lib/bootstrap/css/*.min.css" and exclude reboot, grid, utilities, and RTL variants. Restart ASP.NET Core, request /home/list, and inspect the response HTML; the generated output contains a link for bootstrap.min.css. section 26.4.2

Table 26.6. The built-in tag helper attributes for link elements (view table figure)

Name

Description

asp-href-include

This attribute is used to select files for the href attribute of the output element.

asp-href-exclude

This attribute is used to exclude files from the href attribute of the output element.

asp-append-version

This attribute is used to enable cache busting, as described in the “Understanding Cache Busting” sidebar.

asp-fallback-href

This attribute is used to specify a fallback file if there is a problem with a CDN.

asp-fallback-href-include

This attribute is used to select files that will be used if there is a CDN problem.

asp-fallback-href-exclude

This attribute is used to exclude files from the set that will be used when there is a CDN problem.

asp-fallback-href-test-class

This attribute is used to specify the CSS class that will be used to test the CDN.

asp-fallback-href-test-property

This attribute is used to specify the CSS property that will be used to test the CDN.

asp-fallback-href-test-value

This attribute is used to specify the CSS value that will be used to test the CDN.

Compare stylesheet-selection attributes with cache-busting and CDN-fallback attributes available on link elements. section 26.4.2

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains glob inclusion, exclusion, generated HTML, and browser verification, but defers deeper tag-helper implementation details.
Examples
Uses Bootstrap files, a shared layout, glob exclusions, the /home/list URL, and inspected generated HTML.
What it assumes
Assumes a shared Razor layout, static stylesheet files under wwwroot, and familiarity with CSS file variants.
What you can do after
Apply it via ASP.NET Core link tag helpers and verify the selected stylesheet in browser-rendered HTML.
How it connects
Connects stylesheet selection with link tag helpers, CSS stylesheets, CDN fallback, and cache busting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.