The latest enhancement in .NET 9.0 known as MapStaticAssets is designed to improve the deployment of static asset files. It addresses issues like outdated assets in browsers and allows for the delivery of compressed versions of assets. To include a static file from an asset in a Razor component, you can simply specify its path using the @Asset
directive like this:
<img src="@Assets["/images/picture.jpg"]" />
But what if you need to access your asset file outside of a Razor component, like when setting a background image in CSS? Example:
.section { background-image: url("images/background.jpg"); }