Using ASP.NET Core I am receiving the following token (simplified):
String token = "Z%2F3+3Q==";
The /
is encoded using %2F
. I received the token from a URL called on the client using Angular.
I tried to decode the token using the following:
HttpUtility.UrlDecode(token)
Or
WebUtility.UrlDecode(token)
In both cases %2F
is replaced by /
, which I want, but the +
is replaced by a space, which I do not want.
How do I decode the string?
Update
The client application is sending the token encoded:
Z%2F3%2B3Q%3D%3D;
But, somehow, it seems the token in the following action:
[HttpPut("account/verify/{userId}/{token}")]
public async Task<IActionResult> VerityEmailAddress([FromRoute]AccountEmailVerifyModel model) {
}
Is transformed to:
Z%2F3+3Q==
So the +
and =
are decoded, but the /
is not.
"this/that+other space"
. The result will be"this%2fthat%2bother+space"
. The space gets encoded at+
and the plus sign as%2b
– Crocket+
, the=
and the/
. But somehow the model binder decodes everything but not the/
. I added an update to my question. – CredentialZ/3+3Q==
... And it is a token generated by ASP.NET Core Identity to verify an email address. – Credential+
should be%2B
, the token is malformed. This worked for meHttpUtility.UrlDecode(Encoding.UTF8.GetBytes(token), Encoding.UTF8).Replace(" ", "+");
You can also confirm by having your token toZ%2F3%2B3Q==
and then doHttpUtility.UrlDecode(Encoding.UTF8.GetBytes(token), Encoding.UTF8)
without the replace and it works just fine. – CastleZ%2F3+3Q==
– Castle