Pergunta

In one of my programs I have to process an encrypted Url. I want to save the parameter to a string and I want to keep the special characters as they are

string input_url ="domain.com/auth?token=%2FhKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w";

I want to process the token query string in a decoded form I tried the code

string input_url ="domain.com/auth?token=%2FhKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w";    
val = System.Net.WebUtility.HtmlDecode(input_url.ToString());
val2 = val.Split('=')[1];

But I get the value as %2FhKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w

What i want is val=/hKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w (keep %2F as /, like for other special characters if any exists)

How can I do this?

Foi útil?

Solução 2

System.Net.WebUtility.UrlDecode works with .Net 4 Client profiles only string value_string = Uri.UnescapeDataString(e.Url.Query); wil work for .net 4 applications

Outras dicas

You're using the wrong decoder; this is a URL, not HTML, so try UrlDecode:

  string input_url ="domain.com/auth?token=%2FhKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w";    
  val = System.Net.WebUtility.UrlDecode(input_url);
  val2 = val.Split('=')[1];

This gives the result in val2 of:

  /hKjSuSAO6ctIrgokvB9hmHJPlHQXqTmpuH9fEPWp8w

HTMLDecode is designed for HTML entites such as &.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top