.NET Uri object and encoded forward slashes

When I try to encode forward slashes into a Uri object, it always treats them like regular slashes, and thus changes the request path and resulting in 404 error from server.

I tried:

freeText = "aaa/aaa";

Uri requestUrl = new Uri(string.Format(RestCommand,  Uri.EscapeDataString(freeText)), true);

OriginalString: "https://someurl.com/somepath/aaa%2Faaa"
AbsoluteUri: "https://someurl.com/somepath/aaa/aaa"

The AbsoluteUri is the one that gets executed while I need the OriginalString to be the request's final URL. I saw that the dontEscape flag that I'm using in the ctor is deprecated, is there any alternative to it?

Thanks for your time, everybody
Who is Participating?
Check this:System.Uri constructor evaluates escaped slashes and removes double slasheshttp://connect.microsoft.com/VisualStudio/feedback/details/94109/system-uri-constructor-evaluates-escaped-slashes-and-removes-double-slashes#Looks like it is by design. You can try workaroud posted there.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.