Fabricio
Fabricio

Reputation: 7925

Does AspNet automatically decode url?

I encode strings using HttpUtility.UrlEncode(str).

And I have a method that receives that string via GET, like this:

public ActionResult Confirm(string id)
{
    // ...
}

id is the encoded string received like this:

http://[mysite].com/[ctrler]/Confirm?id=[TheStringEncoded]

Inside Confirm method, I put a HttpUtility.UrlDecode(id), but then it starts to produce errors because the id seems already decoded.

Is the default behavior of asp.net to url decode these params? I'm a bit afraid of its use now, what if it changes depending on some server configuration (I'm wondering), what if some produced string need to decode and others don't? Shall I use HttpUtility.UrlDecode here or not?

PS: the string encoded is in base64. Can I pass that base64 string within ?id= without UrlEncode?

Upvotes: 2

Views: 1164

Answers (1)

Rake36
Rake36

Reputation: 1022

If I recall my MVC correctly, you should encode from the client side. The parameter in the controller method is going to expect clean input. I never had to decode within the controller method.

Upvotes: 3

Related Questions