简体   繁体   中英

Is there any equivalent to JavaScript's decodeURIComponent() in C#?

I'm developing an Ionic app with Angular 7. Unfortunately, facing problem while users are using ' + ' sign in their password. In Angular post request ' + ' sign is replaced by space .

I've found some solutions in stackoverflow and used JavaScript's encodeURIComponent() to encode the passwords. It converts '+' sign to '%2B'.

But, can't find any decoder in my API to decode the ' %2B ' to ' + ' sign. It is noted that my server side is written with ASP.NET (C#). Or, is there any way to send the password with ' + ' sign without converting it ' %2B '

'content-type': 'application/x-www-form-urlencoded'

Sample Password : 'abc+123' Without encodeURIComponent() : 'abc 123' With encodeURIComponent() : 'abc%2B123'

You can try in this way at server side:

string encodedValue="abc%2B123";
string decodedvalue= Uri.UnescapeDataString(encodedValue);
Console.WriteLine(decodedvalue);
-- or
string encodedValue1=HttpUtility.HtmlEncode("abc+123");
string decodedValue1 = HttpUtility.HtmlDecode(encodedValue1);
Console.WriteLine(decodedValue1);

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM