But route is not working & giving me "The resource cannot be found" means 404 error.
I have searched a lot & found that Routing allows this type of route. There are sevaral example like "en-us". But in my case this not working. I am not able to understand why?
Many thanks for ur reply. But this is not the proper way to do this. I have checked microsoft documentation & they clearly mentioned that these Routes work. Check the link below:
"In a URL pattern, you define placeholders by enclosing them in braces ( { and } ). You can define more than one placeholder in a segment, but they must be separated by a literal value. For example,
{language}-{country}/{action} is a valid route pattern. However,
{language}{country}/{action} is not a valid pattern, because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the
language placeholder from the value for the
country placeholder."
above route works fine if Pass all parameters in URL. Means, http://localhost:52018/RoutingTest/search/auto/car-12 works fine with above route. Problem is in case of default parameters only. If I skip any parameter, the route doesn't work means default parameters is not working propetrly in case of "-". separator.
but both above routes work only if I pass all parameters in URL. Default parameters don't work if I use any delimiter except "/" separater. Now, I tried a different approach for testing.
"A path segment cannot contain two consecutive parameters. They must be separated by a '/' or by a literal string."
Now I have a conclusion: If I use any separator or literal or delimiter expect "/" then my default parameters don't work in my route. I will have to pass all parameters in my URL. I can't skip any parameter if I use any other separater other then "/".
I've never attempted a non "/" delimiter, so I can't say for sure but from the wording it sounds like you should be able to use any delimiter you want, but it's hard to say for certain.
I hate to say this but now that all the details have been figured out, and it appears I'm not going to be able to help you a whole lot, you may want to repost this question with these specific details and see if others have a suggestion for you. This thread
is unlikely to get too much other interaction. If you can afford the time, wait a day or so and post again and see what happens.
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
anujrathi
Member
265 Points
124 Posts
Routing doesn't suppot "-" as separator
Jun 18, 2012 09:55 AM|LINK
Hi All,
I am implementing asp.net Routing in my web application.
If I create a route like:
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Routing doesn't suppot "-" as separator
Jun 18, 2012 02:06 PM|LINK
Use it as one route and Split() it on the page to consume.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
anujrathi
Member
265 Points
124 Posts
Re: Routing doesn't suppot "-" as separator
Jun 18, 2012 03:37 PM|LINK
Hi Curt,
Many thanks for ur reply. But this is not the proper way to do this. I have checked microsoft documentation & they clearly mentioned that these Routes work. Check the link below:
http://msdn.microsoft.com/en-us/library/cc668201.aspx#url_patterns
they said:
"In a URL pattern, you define placeholders by enclosing them in braces ( { and } ). You can define more than one placeholder in a segment, but they must be separated by a literal value. For example, {language}-{country}/{action} is a valid route pattern. However, {language}{country}/{action} is not a valid pattern, because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the language placeholder from the value for the country placeholder."
example: {language}-{country}/{action} /en-US/show
Now, what should we do? & I don't think that I am the first person who faced this issue? I searched a lot but i didn't find any solution.
Microsoft says that we can separate placeholders by a litral or delimiter. Can we register these delimiter to work with Routing?
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Routing doesn't suppot "-" as separator
Jun 18, 2012 06:30 PM|LINK
Then I would guess your RouteValueDictionary setup may be the issue. According to the link you sent there may be an issue.
You have:
routes.MapPageRoute("browse-search", "Search/{category}/{subcat}-{subcatID}", "~/Search.aspx", true, new RouteValueDictionary { { "category", "all" }, { "subcat", "all" }, { "subcatID", "0" } });
Shouldn't this be:
routes.MapPageRoute("Search/{category}/{subcat}-{subcatID}", "~/Search.aspx", true, new RouteValueDictionary { { "category", "all" }, { "subcat", "all" }, { "subcatID", "0" } });
Notice the first param needs to be taken off.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
anujrathi
Member
265 Points
124 Posts
Re: Routing doesn't suppot "-" as separator
Jun 19, 2012 04:42 AM|LINK
No, we cann't skip the first parameter because this is the Route Name. No overload of "MapPageRoute" exists without route name.
But we can keep it empty. Like this:
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Routing doesn't suppot "-" as separator
Jun 19, 2012 12:38 PM|LINK
try removing the RouteValueDictionary entry, just for testing.... see if it works without that.
routes.MapPageRoute("", "Search/{category}/{subcat}-{subcatID}/", "~/Search.aspx");
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
anujrathi
Member
265 Points
124 Posts
Re: Routing doesn't suppot "-" as separator
Jun 20, 2012 05:00 PM|LINK
In this case:
http://localhost:52018/RoutingTest/search/auto/car-12 No Error & working fine
http://localhost:52018/RoutingTest/search/auto/car Error(because there is no default parameter)
http://localhost:52018/RoutingTest/search/auto/ Error(because there is no default parameter)
http://localhost:52018/RoutingTest/search/ Error(because there is no default parameter)
http://localhost:52018/RoutingTest/search/auto/car-12 is also working fine if I define default parameters.
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Routing doesn't suppot "-" as separator
Jun 20, 2012 05:24 PM|LINK
Hmmm.... weird indeed..
Can you test with using the defaults but on a simplier route (one with no "-" in it)?
Just to see if it's the "-" or the RouteValueDictionary that's causing the issue(s).
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
anujrathi
Member
265 Points
124 Posts
Re: Routing doesn't suppot "-" as separator
Jun 20, 2012 07:25 PM|LINK
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: Routing doesn't suppot "-" as separator
Jun 20, 2012 08:22 PM|LINK
Weird indeed.....
I've never attempted a non "/" delimiter, so I can't say for sure but from the wording it sounds like you should be able to use any delimiter you want, but it's hard to say for certain.
I hate to say this but now that all the details have been figured out, and it appears I'm not going to be able to help you a whole lot, you may want to repost this question with these specific details and see if others have a suggestion for you. This thread is unlikely to get too much other interaction. If you can afford the time, wait a day or so and post again and see what happens.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!