0

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?

5
  • you must config routing configurations to ignore cases. Commented Jan 3, 2014 at 13:59
  • But there may be many cases ... or can be reduced to one? Sorry for my english. Commented 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. Commented Jan 3, 2014 at 14:07
  • Yes, I want to ignore symbol Commented 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? Commented Jan 3, 2014 at 14:33

2 Answers 2

3

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
    );
}
Sign up to request clarification or add additional context in comments.

6 Comments

how to ignore characters (') in the URL?
So '*' after action solves that? have you ever tested that?
@AmirHosseinMehrvarzi Yes It is working fine and I have tested it.
@SergeyYanchenko you can try this.It is working for me
@BhaveshKachhadiya how it filters according to my last comment followed in question?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.