Is MVC2 ASP.Net URLDecoding automatically?
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 MapRou开发者_开发知识库te. 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.
Yes, MVC automatically url decodes action parameters. But you can still access the url encoded version through query string.
So what I did was to Base64 encode instead of URLEncode my AES encrypted data in my Action Parameter.
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();
}
精彩评论