0

Similar to this question, I have problems with a backslash in my route parameter. The parameter presents a windows folder and subfolder structure, which contains backslashes.

However, every browser (Chrome, Firefox, IE) converts the backslash automatically to a slash.

Controller/Action/Myfolder\Mysubfolder\AnotherSubfolder

Always becomes:

Controller/Action/Myfolder/Mysubfolder/AnotherSubfolder
Community
  • 1
  • 1
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
  • use POST body to send Mysubfolder\AnotherSubfolder parameter – Karthik M R May 09 '16 at 07:53
  • `The parameter presents a windows folder and subfolder structure, which contains backslashes.` - forward slashes are the convention for representing directory structures on the web. Just use a catch-all route and convert them. Have you *ever* seen a URL with backslashes in it? – Ant P May 09 '16 at 07:54
  • Just for awareness: https://www.owasp.org/index.php/Path_traversal – TGlatzer May 09 '16 at 08:57

1 Answers1

2

The parameter presents a windows folder and subfolder structure, which contains backslashes.

Encode the parameter and add it in the URL, in your controller you can decode it back to original value.

Encode your value using HttpUtility.UrlEncode(value);

Decode it like HttpUtility.UrlDecode(value);

Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59