当字符串通过 javascript 中的 encodeURIComponent 时,将字符串解析为原始形式

Parsing the string to original form when string comming through encodeURIComponent in javascript

本文关键字:字符串 原始 javascript 中的 encodeURIComponent      更新时间:2023-09-26

我已经将密码作为参数从ajax发送到我的WCF服务方法之一。

在发送密码时,因为它可以包含"#",我在javascript中使用了:

var encodedPassword = encodeURIComponent(Password); 

现在它使用 %23 ...等

但是当涉及到 c# 中的服务方法时,它带有相同的形式,即"%23"代替"#"。

我想将其解码为普通字符串。

为此,我尝试了:

Password = HttpUtility.HtmlDecode(Password);

这件事失败了。

Password = HttpUtility.UrlDecode(Password);

这件事失败了。

那么我怎样才能再次将密码解码为原始形式???(里面有#)

尝试取消转义数据字符串:

Password = System.Uri.UnescapeDataString(Password);

Dotnetfiddle