---
title: "Generate SEO-Friendly Slugs from Titles in ASP.NET Core"  
description: "Generate SEO-Friendly Slugs from Titles in ASP.NET Core"  
author: "ICSM Computer"  
published: 2025-02-09  
updated: 2025-02-09  
canonical: https://www.mindstick.com/blog/305228/generate-seo-friendly-slugs-from-titles-in-asp-dot-net-core  
category: ".net core"  
tags: ["c#", "core framework", ".net core"]  
reading_time: 2 minutes  

---

# Generate SEO-Friendly Slugs from Titles in ASP.NET Core

To create shorter, user-friendly, or "slugged" URLs with Latin-based names, you can use URL slugging. This process typically involves [converting strings](https://www.mindstick.com/forum/160330/describe-the-parseint-and-parsefloat-functions-and-their-use-in-converting-strings-to-numbers) (like page titles or names) into lowercase, replacing spaces and special [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-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](https://www.mindstick.com/blog/300788/why-is-heart-attack-increasing-in-the-younger-generation)**

A utility method can [convert any string](https://www.mindstick.com/interview/33830/how-to-convert-any-string-into-upper-case-in-sql-server) into a slug-friendly format.

```cs
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](https://www.mindstick.com/articles/249204/generator-info-where-can-you-find-the-best-generator-for-power-outages) in [Your Application](https://www.mindstick.com/forum/34702/please-tell-me-what-is-cross-site-scripting-and-how-is-it-harmful-for-your-application)**

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

**Example in [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc):**

```cs
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

#### 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](https://yourviews.mindstick.com/view/87465/how-to-enhance-your-content-visibility-10-tips). 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](https://www.mindstick.com/services/search-engine-optimization) and [user experience](https://www.mindstick.com/articles/12731/the-importance-of-feedback-to-the-user-experience).

---

Original Source: https://www.mindstick.com/blog/305228/generate-seo-friendly-slugs-from-titles-in-asp-dot-net-core

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
