This project is read-only.

How does Orchard make "pretty urls"?

Topics: General
Oct 20, 2014 at 1:24 AM
Edited Oct 20, 2014 at 1:52 AM
How does Orchard do this? For example, if the title is "Nice Looking Slug" then it becomes:

Can you point me to the source code, or show me how Orchard does it?
Oct 20, 2014 at 5:17 PM
Edited Oct 20, 2014 at 5:18 PM

Orchard takes advantage of the normal MVC Routing. Take a look at Orchard.AutoRoute and Orchard.Alias.

It get's all defined routes from the database and adds them to the RouteCollection.

public void GetRoutes(ICollection<RouteDescriptor> routes) {
    foreach (RouteDescriptor routeDescriptor in GetRoutes()) {

public IEnumerable<RouteDescriptor> GetRoutes() {
    var distinctAreaNames = _blueprint.Controllers
        .Select(controllerBlueprint => controllerBlueprint.AreaName)

    return distinctAreaNames.Select(areaName =>
        new RouteDescriptor {
            Priority = 80,
            Route = new AliasRoute(_aliasHolder, areaName, new MvcRouteHandler())
Oct 20, 2014 at 5:20 PM
It is called 'Slugify'. Basically you just take the string, lowercase all letters and replace the spaces with something else like a '-'.

In pseudo code it would look something like this:
    .ReplaceAll(" ", "-")
Pretty simple. Then just store the slug with your item, and write a method that retrieves the item that is stored with that particular slug.