The new ASP.NET routing is great for simple path style URL's but if you want to use a url such as:
http://example.com/items/search.xhtml?term=Text+to+find&page=2
Do you have to use a catch all parameter with a validation?
The new ASP.NET routing is great for simple path style URL's but if you want to use a url such as:
http://example.com/items/search.xhtml?term=Text+to+find&page=2
Do you have to use a catch all parameter with a validation?
Any view data items that are not listed in the route are automatically mapped to the querystring, so if you map "items/search.xhtml" to an action:
Search(string term, int page)
Then you should get the results you are looking for.
I was also having trouble passing an encoded URL to a route as a route parameter.
You can't use url encoded chars in a URL, but you can in a query string.
Therefore I needed my route to also have a query string element to it.
Say I have a route:
MapPageRoute("myroute", "myroute/{x}", "~/routehander.aspx")
But I want it in the form of:
http://mywebsite.com/myroute/{x}?url=myurl
We can do this:
Dim x as integer = 12
Dim rvd As New Routing.RouteValueDictionary
rvd.Add("x", x)
rvd.Add("url", Server.UrlEncode("/default.aspx"))
HttpContext.Current.ApplicationInstance.Response.RedirectToRoutePermanent("myroute", rvd)
This would redirect us to the following url:
http://mywebsite.com/myroute/12?url=%252fdefault.aspx