MVC2 Slash char in url - asp.net-mvc-2

I want to use encrypted strings in MVC2 urls. A typical url in my app looks like this:
http://localhost:29558/Account/PasswordReset/ZKGeDMZikfIsnO8/MEs7SCBlI+MZo1Je8LM5dTEeCt3u91ARPUcavT5UXfVVRfyE
Note that everything after PasswordReset/ is the encrypted string. In the example the encrypted string contains a slash, and this is causing MVC to crash.
I've tried adding a MapRoute in Global.asax.cs as follows:
routes.MapRoute(
"PasswordResetSpecialCase", // Route name
"Account/PasswordReset/*", // URL with parameters
new { controller = "Account", action = "PasswordReset" } // Parameter defaults
);
but MVC2 is still falling over because the encrypted string contains a slash char. If I remove the slash then it works, but obviously that's no good.
How do I get MVC2 to regard everything after the PasswordReset as pure data?
Thanks.

Your maproute contains an error. Replace the * with {*nameOfParameter}

Related

Spring MVC Rest, invoking using URL, escape characters & causing issue for getting the value in controller

I have a controller mapping as below
#RequestMapping(value = { "/search"}, method = RequestMethod.GET)
public #ResponseBody
Object searchProducts(#PathVariable("query") String query,
#RequestParam(value = "param1", required = false) String param1,
#RequestParam(value = "param2", required = false) String param2,)
when i use url as given below it works fine i even get the value populated by spring
http://host/app_name/search?param1=[value]&param2=[value]
But when escape character is used it breaks
http://host/app_name/search?param1=[value]&param2=[value]
Is there any configuration in springcontext or web.xml which will allow me to take care of encoding automatically ??
i have already tried setting below contect in web.xml but it does not work
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
& is an HTML escape sequence, and there are no requirements to treat it as & in URLs. Therefore it would be better to fix your internal system in order to make it generate correct URLs.
However, if you cannot do it for some reason, you can solve this problem in the following (hackish) way:
Create a Filter that would wrap original HttpServlerRequest into your subclass of HttpServlerRequestWrapper.
In that subclass create a map of "fixed" parameters (i.e. get parameters from the original request and create a new parameter map by stripping amp; from the begining of parameter names) and override getParameter*() methods to use that map.
Would make sense that Spring would treat it as part of the value, '&' is HTML encoded, not URL encoded.
I would try to figure out why the system is HTML encoding the '&' as '&' rather than building a proper GET string.
If you want to actually include an ampersand within the value of GET parameters, use %26 which decodes into '&' when passed through a URL.
Try:
HtmlUtils.htmlUnescape(query);

zend: baseUrl view helper returns empty string

On my site, when I call $this->baseUrl() in a view, it returns an empty string. I would expect it to return e.g. http://www.foobar.com/. Do I need to manually set base url?
In manual to Zend_Application_Resource_Frontcontroller - configuration keys, I have just found this:
baseUrl: explicit base URL to the application (normally auto-detected)
Any ideas why it is not autodetected for me?
The baseUrl() helper returns the path to your Zend Application.
Use the serverUrl() helper for the hostname.
Did you set the baseurl in your application.ini?
resources.frontController.baseUrl = "/subdir"
Manual

zend, getting a param that a value of http://

im trying to get a param from my url.. via $this->_request->getParam('url')
so, /url/http://www.yahoo.com
but the value of param url is h because theres forward slashes in the value..
how can i get the full url... as now, its thinking that the http:// is another param..
public function getUrlToGo(){
$url=$this->_request->getParam('url');
if ($url='http://www.yahoo.com'){
return $this->_forward("findyahoo", "urlclass");
}
}
Usually when urls are passed in the address bar the slashes (and most other characters) are converted into url-safe characters.
<?php
$url = urlencode('http://www.yahoo.com');
echo $url; //http%3A%2F%2Fwww.yahoo.com
You can then use urldecode($url) to get the original url back.

ASP.NET MVC Route parameter separate by ":" char

Now I am not sure it practical or not but I like to have a URL like this
http://example.com/field1_query:field2_query map but it seem like ASP.NET MVC Routing not happy with the ":" char here my route
routes.MapRoute("filter",
"{field1_query}:{field2_query}",
new { controller ="...", action="..."} );
It doesn't work but if I change to {field1_query}/{field2_query} it works fine (which mean my URL also change http://example.com/field1_query/field2_query).
The colon is a reserved character in a URL. See the IETF spec. You would need to escape any restricted or reserved characters.

ASP.NET MVC 2 wildcard route has trouble handling spaces

I've got a wildcard route mapped as below:
routes.MapRoute(
null,
"{controller}/{action}/{*category}",
new { controller = "Mall", action = "Index", category = UrlParameter.Optional }
);
This has been working fine until the category has any spaces before or after slashes " / ".
For the category ART/MUSIC, it will find the page fine.
For the category ART / MUSIC, it will give me a 404 not found.
Any help would be much appreciated!
I've just answered kind of the same question here. For completeness:
If an empty space is at the end of any section of the URL before the next slash, it throws a HttpException in the System.Web.Util.FileUtil.CheckSuspiciousPhysicalPath() method which is handled by MVC and you'll get a HTTP 404 response.
You can verify that yourself by checking the checkbox for Throw in:
Visual Studio
Debug
Exceptions
Common Language Runtime Exceptions
Generally you should not have empty spaces in your URLs. I personally format my urls, that all spaces becomes a dash (-).