🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Generate SEO-Friendly Slugs from Titles in ASP.NET Core

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

To create shorter, user-friendly, or "slugged" URLs with Latin-based names, you can use URL slugging. This process typically involves converting strings (like page titles or names) into lowercase, replacing spaces and special characters with hyphens or other valid URL characters, and ensuring the resulting URL is unique and human-readable.






Example: Generating Latin Name Slugs for URLs in ASP.NET Core









Create a Utility Method for Slug Generation



A utility method can convert any string into a slug-friendly format.




CODE
using System.Text;
using System.Text.RegularExpressions;
public static class UrlSlugger
{
public static string GenerateSlug(string input)
{
if (string.IsNullOrEmpty(input))
return string.Empty;

// Convert to lowercase
input = input.ToLowerInvariant();

// Remove diacritics (accents) from Latin characters
input = RemoveDiacritics(input);

// Replace spaces and invalid characters with hyphens
input = Regex.Replace(input, @"[^a-z0-9\s-]", ""); // Allow only alphanumeric, spaces, and hyphens
input = Regex.Replace(input, @"\s+", "-").Trim(); // Replace spaces with hyphens
input = Regex.Replace(input, @"-+", "-"); // Replace multiple hyphens with a single one

return input;
}

private static string RemoveDiacritics(string text)
{
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();

foreach (var c in normalizedString)
{
var unicodeCategory = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != System.Globalization.UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}

return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
}












Using the Slug Generator in Your Application



You can use this slug generator for URLs when defining routes or generating links dynamically.



Example in Controller:




CODE
public IActionResult GenerateSluggedUrl(string title)
{
string slug = UrlSlugger.GenerateSlug(title);
return Ok($"Generated slug: {slug}");
}






Example Usage:

For a title like "Éxample Title for URL!", the slug will be:




example-title-for-url








Integrating Slugs in Routing



To use slugs in your routing, you can define a route pattern with a {slug} parameter and parse the slug dynamically.



Example in Program.cs:




CODE
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "sluggedRoute",
pattern: "page/{slug}",
defaults: new { controller = "Page", action = "Details" });

// Default route
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});






Example in PageController:




CODE
public class PageController : Controller
{
public IActionResult Details(string slug)
{
// Retrieve the page data by the slug
return View(model: $"Page with slug: {slug}");
}
}












Testing Slugged URLs



Example URLs:

/page/example-title-for-url

/page/sample-page-title

Result:

You can use the slug parameter in the controller to load content based on the slug (e.g., querying the database for matching pages).









Additional Tips




  • Ensure slugs are unique for your content. Add a database field to store slugs and validate uniqueness.

  • Store slugs in your database alongside the corresponding entity (e.g., articles, pages, or products).

  • Use slugs in links to improve SEO and user experience.



Thanks

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
cPanel ConfigServer Security & Firewall Vulnerability Allows Remote Attacker to Execute Arbitrary Commands
1 Quelle
New Android Ransomware Records Screens, Steals OTPs and Secretly Takes Photos of Victims
1 Quelle
Conti Ransomware Hacker Sentenced After Group Attacked Over 1,000 Victims Worldwide
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Generate SEO-Friendly Slugs from Titles in ASP.NET Core

Thematisch verwandte Begriffe: Generate, SEOFriendly, Slugs, from · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...