Please, give me an advice on the following question: there's a usual string like here : /Search/Index, and a user inputs a char accidentally: /Search/Index'. How should I ignore the сhar and make a user simply follow the link Search/Index?
-
you must config routing configurations to ignore cases.Amirhossein Mehrvarzi– Amirhossein Mehrvarzi2014-01-03 13:59:50 +00:00Commented Jan 3, 2014 at 13:59
-
But there may be many cases ... or can be reduced to one? Sorry for my english.SERGEY YANCHENKO– SERGEY YANCHENKO2014-01-03 14:04:57 +00:00Commented Jan 3, 2014 at 14:04
-
That listed in Global.asax or RouteConfig file. that's very simple and easy to understand and changable by you.Amirhossein Mehrvarzi– Amirhossein Mehrvarzi2014-01-03 14:07:14 +00:00Commented Jan 3, 2014 at 14:07
-
Yes, I want to ignore symbolSERGEY YANCHENKO– SERGEY YANCHENKO2014-01-03 14:14:55 +00:00Commented Jan 3, 2014 at 14:14
-
I must mention that there is main difrence between actions that ended with some additional unwanted characters. That can be : 1-alphabet/numeric that can change action name 2-meaningful like URL encoded/decoded 3-meaningless I think you want to remove meaningless ones. true?Amirhossein Mehrvarzi– Amirhossein Mehrvarzi2014-01-03 14:33:50 +00:00Commented Jan 3, 2014 at 14:33
Add a comment
|
2 Answers
you can add this code block in your Global.asax file.
The line "{controller}/{action*}/{id}" have {action*} so action will be index and any characters after index will consider as ignored and route to the index action.
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action*}/{id}", // URL with parameters
new { controller = "Search", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
6 Comments
SERGEY YANCHENKO
how to ignore characters (') in the URL?
Amirhossein Mehrvarzi
So '*' after
action solves that? have you ever tested that?Bhavesh Kachhadiya
@AmirHosseinMehrvarzi Yes It is working fine and I have tested it.
Bhavesh Kachhadiya
@SergeyYanchenko you can try this.It is working for me
Amirhossein Mehrvarzi
@BhaveshKachhadiya how it filters according to my last comment followed in question?
|
I think this is not advisable. This would result in multiple urls for the same ressource and your searchengine ranking might suffer. It might be better to just return a 404
http://moz.com/blog/canonical-url-tag-the-most-important-advancement-in-seo-practices-since-sitemaps