views:

88

answers:

3

So I was calling the Controller in MVC2 like this and I accessed the classic querystrings just fine. Please notice that the second parameter thing2 is URLEncoded already and again retrieving the URLEncoded querystring and URLDecoding is no problem. My example looks like this...

http://mydomain.com/controller?thing1=1544&thing2=somethingURLEncoded

Now I try to move to the MVC2 ASP.Net way of handling parameters and make myself a nice custom MapRoute. I test it to see that it works with a simple test...

http://mydomain.com/controller/Index/1544/999

I debug with VS2010 step inside of my Index method inside of my controller with success!

I then decide to take the next step and change the last parameter on the URL to be a URLEncoded value...

http://mydomain.com/controller/Index/1544/somethingURLEncoded

Problem I see after executing this in my browser is that it almost looks like MVC2 ASP.Net is automagically URLDecoding this before I get to step inside of my Index method inside of my controller.

What gives? I thought I would be able to get inside of my controller first and the secondly do a URLDecode of my own. Because the orginal data was AES encrypted and had forward slashes in it.., have my parameter prematurely URLDecoding is not a side effect I can plan around.

Please help.

A: 

As ASP.NET MVC is based on ASP.NET engine (not surprisingly), properly encoded URLs are automatically properly URL decoded by the engine so you don't ever need to ask questions. Simply:

public ActionResult Index(string q)
{
    // TODO : Use the q parameter here as is without ever caring of URL decoding it.
    // It's the caller of this action responsibility to properly URL encode his data
    return View();
}
Darin Dimitrov
I get an 404.11 showing my AES encrypted parameter data before I ever hit the Index method in my controller. The AES encrypted data has forward slashes in it. It looks to me that the routing engine in MVC2 gets the AES encrypted data rather than the URLEncoded data because it can't get to the destination Index method in my controller either.
apolfj
Why do you need to AES encode? What slashes are you talking about? Are you sure the client properly URL encoded? Why using GET instead of POST for such thing? By the way forward slashes break everything in a route, so avoid them.
Darin Dimitrov
Yes it must be AES encrypted. AES uses forward slashes as a possible result after encryption. Yes I am positive it is URLEncoded because again if I use querystring instead of parameter routing I can URLDecode and it works great as I stated in my initial question. These URLs come from Hyperlinks. This is why it is GET and not POST.
apolfj
Is there anyway to stop the automatic URL decoding of MVC2 ASP.Net or at least get involved with when it does this step and stop it then ask it to do it after I get to my controller?
apolfj
A: 

Yes, MVC automatically url decodes action parameters. But you can still access the url encoded version through query string.

Necros
Is there anyway to change the time in which the URLDecode happens so that it is the last thing to happen just before my action method is called in my controller?
apolfj
I don' think so, but why would you care, when url encoded version is still accessible?
Necros
A: 

So what I did was to Base64 encode instead of URLEncode my AES encrypted data in my Action Parameter.

apolfj