ASP.NET Core: Why Your Sitemap URLs Look Wrong (Url.Action vs Url.RouteUrl)

December 11, 2025
ASP.NET Core: Why Your Sitemap URLs Look Wrong (Url.Action vs Url.RouteUrl)

Watch the Video

Or watch it directly on YouTube: Click here

Video Description

Your sitemap is generating ugly URLs like /home/displaypage?name=training instead of clean URLs like /training. Here's the fix - and why it happens.

What you'll learn:

  • Why Url.Action ignores your custom routes
  • How Url.RouteUrl uses named routes instead
  • The "inside-out vs outside-in" mental model
  • When to use each approach
  • How named routes connect URL patterns to your code

The fix:

// Before - builds from code structure
var url = Url.Action("DisplayPage", "Home", new { name = page.Name }, Request.Scheme);

// After - uses your named route pattern
var url = Url.RouteUrl("page", new { name = page.Name }, Request.Scheme);

Key insight: Url.Action works "inside-out" from your code structure. Url.RouteUrl works "outside-in" from the URL patterns you designed.

What ASP.NET gotchas have tripped you up? Let me know in the comments!

Chapters

  • 0:00 The Problem: Ugly Sitemap URLs
  • 0:13 The Offending Code
  • 0:35 Url.Action() Ignores Your Routes
  • 0:52 The Fix: Use Url.RouteUrl()
  • 1:10 How Named Routes Work
  • 1:45 Inside-Out vs Outside-In
  • 2:36 When to Use Each
  • 3:08 Quick Recap

Video Info

  • Duration: 3:56
  • Published: December 11, 2025

Links

Categories: Video YouTube