Encoding Issues \ Decoding Strings JS & # 8596; WITH#

I have a problem with JS encoding and then with extension on C # server. I use the javascript encode () function, but when I have special characters like +, C # has httputility.urldecode () → and it converts it as if it were a SPACE char.

What is the best way to transmit JS encoding and decoding C #?

I have <a href='javascript:foo(escape('hello +'))' />

function foo(data)
{
$.ajax({ url: "http:/....." + data, dataType: 'html', context: document.body
...
...
}

I debugged the server and I get "hello ++" - it does not know what + is (space or +), Thanks!

+3
source share
3 answers

Javascript encodeencodes html. Since +valid in HTML, it does nothing for +.

URL- - + URL- .

javascript encodeURIComponent, + :

<a href='javascript:foo(encodeURIComponent('hello +'))' />

, HTML URL .

+2

JavaScript:

escape(string);

#:

Microsoft.JScript.GlobalObject.unescape(string);

.

+2

There is no need to do encoding in javascript and decode in C #. Just use the javascript 'encodeURIComponent (string) function and you don't need to make any changes to the C # code.

-1
source

Source: https://habr.com/ru/post/1769131/


All Articles