Overview
Cuemon.Extensions.AspNetCore.Mvc.RazorPages adds Razor Pages-specific URL helpers for page classes that inherit PageBase. It extends Cuemon.AspNetCore.Razor.TagHelpers by letting page code resolve application and CDN asset URLs from the same option objects that drive the tag helpers.
Both extension methods resolve their options from HttpContext.RequestServices, then append an ICacheBusting version token when one is registered. The test suite exercises both page-local assets and CDN assets through Razor Pages endpoints, which shows the package is meant to keep page-model code aligned with the URL policy already configured for the view layer.
Key APIs
GetAppUrl builds an application asset URL for a PageBase instance by combining the configured AppTagHelperOptions base URL with the relative asset path passed to the method. If an ICacheBusting service is available in the request services, it appends ?v={Version} to the generated URL.
GetCdnUrl follows the same request-scoped pattern for CdnTagHelperOptions, which makes it the package entry point for assets hosted outside the application itself. The tests verify both plain and cache-busted CDN output, including an HTTPS base URL.
Basic usage
Use this pattern when a Razor Page needs to generate the same application and CDN asset URLs that your Cuemon tag helpers already use in markup. It matters because page-model code, rendered HTML, and optional cache-busting stay on one URL-formatting path instead of duplicating base-URL rules in multiple places.
using System.Threading.Tasks;
using Codebelt.Extensions.Xunit;
using Cuemon.AspNetCore;
using Cuemon.AspNetCore.Razor.TagHelpers;
using Cuemon.Extensions.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Xunit;
namespace Contoso.Web.Tests;
public class AssetPageUrlTest : Test
{
public AssetPageUrlTest(ITestOutputHelper output) : base(output) { }
[Fact]
public void ShouldResolveAssetUrls_FromConfiguredTagHelperOptions()
{
var services = new ServiceCollection();
services.AddSingleton(Options.Create(new AppTagHelperOptions { Scheme = ProtocolUriScheme.Relative, BaseUrl = "static.cuemon.net" }));
services.AddSingleton(Options.Create(new CdnTagHelperOptions { Scheme = ProtocolUriScheme.Https, BaseUrl = "nblcdn.net" }));
var page = new AssetPage
{
PageContext = new PageContext
{
HttpContext = new DefaultHttpContext { RequestServices = services.BuildServiceProvider() }
}
};
var appUrl = page.GetAppUrl("img/hero-solution.jpg");
var cdnUrl = page.GetCdnUrl("img/devops-factory.png");
TestOutput.WriteLine($"App asset: {appUrl}");
TestOutput.WriteLine($"CDN asset: {cdnUrl}");
Assert.Equal("//static.cuemon.net/img/hero-solution.jpg", appUrl);
Assert.Equal("https://nblcdn.net/img/devops-factory.png", cdnUrl);
}
private sealed class AssetPage : PageBase
{
public override Task ExecuteAsync() => Task.CompletedTask;
}
}
Installation
dotnet add package Cuemon.Extensions.AspNetCore.Mvc.RazorPages
Usage guidance
Use this package when your Razor Pages application already relies on Cuemon.AspNetCore.Razor.TagHelpers and you want page classes to emit matching asset URLs from code. If you only need URL formatting in tag helpers or you do not have page-level logic that builds asset paths, stay on the lower-level tag helper package and plain Razor Pages APIs.
Family packages
- 📦Cuemon
- 📦Cuemon.AspNetCore
- 🔐Cuemon.AspNetCore.Authentication
- 🔐Cuemon.AspNetCore.Authorization
- 📦Cuemon.AspNetCore.Diagnostics
- 🌐Cuemon.AspNetCore.Http
- 📦Cuemon.AspNetCore.Mvc.Filters
- 📦Cuemon.AspNetCore.Mvc.Formatters.Json
- 📦Cuemon.AspNetCore.Mvc.TagHelpers
- 📦Cuemon.AspNetCore.Razor.TagHelpers
- 📦Cuemon.Collections.Generic
- ⚙️Cuemon.Configuration
- ⚙️Cuemon.Core
- 📦Cuemon.Data
- 🔐Cuemon.Data.Integrity
- 📦Cuemon.Diagnostics
- ☁️Cuemon.Extensions.Aws
- ⚙️Cuemon.Extensions.AspNetCore.Configuration
- 📦Cuemon.Extensions.Collections.Generic
- ⚙️Cuemon.Extensions.Configuration
- 📦Cuemon.Extensions.Data
- 📦Cuemon.Extensions.Diagnostics
- 📦Cuemon.Extensions.Globalization
- 📦Cuemon.Extensions.Hosting
- 📦Cuemon.Extensions.IO
- 📦Cuemon.Extensions.Net
- 📦Cuemon.Extensions.Newtonsoft.Json
- 📦Cuemon.Extensions.Reflection
- 📦Cuemon.Extensions.Swashbuckle.AspNetCore
- 📦Cuemon.Extensions.Text.Json
- 📦Cuemon.Extensions.Threading
- 📦Cuemon.Extensions.Xml
- 📦Cuemon.IO
- ⚙️Cuemon.Kernel
- 📦Cuemon.Net
- 📦Cuemon.Resilience
- 📦Cuemon.Runtime.Caching
- 🔐Cuemon.Security.Cryptography
- 📦Cuemon.Threading
- 📦Cuemon.Xml