2

I have run into a problem when encoding a URL. I understand the differences between UrlPathEncode and UrlEncode, but I seem to have run into an instance where neither will help.

I want to encode the following my-page-???-testing. When using UrlPathEncode it ignores anything after the first ?, and UrlEncode escapes all spaces into +, which is not what I want.

Is there a method I could use to encode question marks too?

Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111
TheGateKeeper
  • 4,420
  • 19
  • 66
  • 101
  • 4
    What is the problem with encoding spaces into `+`. This is the standard way to encode urls so saying that you don't want to do this is likely to result in it just being custom code (eg find and replace type things). Also if you don't want the space to + then you might want to edit your title since you don't want full encoding. ;-) – Chris Dec 27 '12 at 14:49
  • 6
    As `?` is integral to traditional querystring name/value pairs, I'm not sure it's a valid target character for encoding. It may well be a "roll-your-own" solution. – SpaceBison Dec 27 '12 at 14:49
  • did you try HtmlEncode... http://stackoverflow.com/questions/1144535/c-sharp-htmlencode-from-class-library – malkassem Dec 27 '12 at 14:52
  • Chris, encoding space into `+` is only valid in the query string portion of the url. All other spaces must be encoded into `%20`. – TheGateKeeper Dec 27 '12 at 15:02

0 Answers0