Search code examples
asp.net-mvcumbracoumbraco7

Umbraco - Encode URL following the same rules as defined in the request handler settings


In Umbraco, i want to generate URL encoded string as it was a genuine Umbraco path.

So if i have the following relative path:

/products/4/drinking glass

I want it encoded like this:

/products/4/drinking-glass/

As it would if i used NiceUrl on a published content object. Following the same rules as described in the request handler part of umbracoSettings.config.

Is there a way to do that?


Solution

  • I found the answer after searching a bit more.

    Umbraco made an extension method for this purpose:

    "drinking glass".ToUrlSegment()
    

    Which provides a safe way to generate custom url encoded strings.