0

I created the custom link on the asp.net core project. And i tried to getting parameters in the link on the controller.

i need to prmtr1 and prmt2 values but '+' char in the prmtr1 return to ' '(space) value. I must get 'j+vNMbBKUGU=' but im getting 'j vNMbBKUGU='

enter image description here

 link: blablabla/contract?prmtr1=j+vNMbBKUGU=&prmtr2=BIIOnHXUgGM=

if i change space char to + char, my problem fixed but i think it's not good idea. I hope you can help me. Thanks.

  • Hi, this string is dynamic. I encrypt id numbers with md5. so the + character is not a character I gave it to. – Enes KAYGUSUZ Jul 01 '21 at 11:53
  • You can do a string replace, or you can do a POST instead of a get so that the value is not in the URL. Or you can base62 encode instead of base64. – Crowcoder Jul 01 '21 at 11:57
  • It's not clear how you're constructing your link, but in a URL, a `+` means a space character. There are many characters which are invalid in URLS, as well. You need to be careful when constructing a URL, and make sure that it's properly escaped. – canton7 Jul 01 '21 at 11:58

1 Answers1

0

asp.net assumes that the "+" character is an encoded " " and therefore convert it to a space character. In javascript you can use the function encodeURIComponent(string) to encode your parameters before sending.

You can read more about the function here: https://www.w3docs.com/snippets/javascript/how-to-encode-javascript-url.html#the-encodeuricomponent-function-5

And you can find more information about why this is happening here: https://stackoverflow.com/a/2678602/16154479

René
  • 100
  • 1
  • 8