Take the community feedback survey now.

sunylcumar
May 13, 2025
  527
(5 votes)

Helper method to encode query string properly

When using Url.ContentUrl() in Optimizely 12, encodes spaces as + in the query string. If you want to encode the spaces as %20, use the below helper method.

 public static string GetEncodedUrl(string href)
 {
     var decodedHref = System.Web.HttpUtility.UrlDecode(href);
     int questionMarkIndex = decodedHref.IndexOf('?');
     string path = questionMarkIndex >= 0 ? decodedHref.Substring(0, questionMarkIndex) : decodedHref;
     var relativeUrl = UrlResolver.GetUrl(path);
     string query = questionMarkIndex >= 0 ? decodedHref.Substring(questionMarkIndex + 1).Replace("&", "&") : string.Empty;     
     var encodedQuery = !string.IsNullOrEmpty(query) ? $"?{Uri.EscapeUriString(query)}" : query;
     return $"{relativeUrl}{encodedQuery}";
 }
May 13, 2025

Comments

El Magnifico
El Magnifico May 18, 2025 02:14 PM

works well

Manoj Kumawat
Manoj Kumawat May 20, 2025 07:37 AM

Hi, thank you for sharing your insights and contributing to the community.

That said, I wanted to share some constructive feedback. Some of the posts could benefit from a bit more context around the problem being addressed. Providing additional background can help readers better understand the issue and how your solution applies.

Additionally, I've noticed that many posts seem to have the same reviewer, which raises some concerns about objectivity. It's important that content on World Optimizely not only be informative but also genuinely helpful and independently reviewed.

I hope you take this feedback in the spirit it's intended to support continued improvement. Wishing you all the best, and thank you again for contributing.

sunylcumar
sunylcumar May 22, 2025 03:48 PM

Hi Manoj,

First of all I thank you for your suggestion about providing the context of the problem and I agree with you. I will try to explain the problem and solutions in my future posts.

FYI, The other reviewer is my friend for whom I post the solutions here instead of just helping him

Thanks

Sunil

Please login to comment.
Latest blogs
Optimizely CMS Mixed Auth - Okta + ASP.NET Identity

Configuring mixed authentication and authorization in Optimizely CMS using Okta and ASP.NET Identity.

Damian Smutek | Oct 27, 2025 |

Optimizely: Multi-Step Form Creation Through Submission

I have been exploring Optimizely Forms recently and created a multi-step Customer Support Request Form with File Upload Functionality.  Let’s get...

Madhu | Oct 25, 2025 |

How to Add Multiple Authentication Providers to an Optimizely CMS 12 Site (Entra ID, Google, Facebook, and Local Identity)

Modern websites often need to let users sign in with their corporate account (Entra ID), their social identity (Google, Facebook), or a simple...

Francisco Quintanilla | Oct 22, 2025 |

Connecting the Dots Between Research and Specification to Implementation using NotebookLM

Overview As part of my day to day role as a solution architect I overlap with many clients, partners, solutions and technologies. I am often...

Scott Reed | Oct 22, 2025

MimeKit Vulnerability and EPiServer.CMS.Core Dependency Update

Hi everyone, We want to inform you about a critical security vulnerability affecting older versions of the EPiServer.CMS.Core  package due to its...

Bien Nguyen | Oct 21, 2025

Speeding Up Local Development with a Fake OpenID Authentication Handler

When working with OpenID authentication, local development often grinds to a halt waiting for identity servers, clients, and users to be configured...

Eric Herlitz | Oct 20, 2025 |