D
D
Dmitry Guketlev2010-12-02 19:34:34
ASP.NET
Dmitry Guketlev, 2010-12-02 19:34:34

ASP.NET MVC Framework special character encoding?

Good evening Habr!
I recently started learning ASP.NET MVC Framework and came across the following issue. Let's say I want to make a controller for searching the site like /search/<word>. But after all, the user can enter anything into the search, including / and * and other special characters, but .NET, according to my feelings, first translates the characters from “percent encoding” to “normal form” and only then determines which controller to transfer.
Suppose the user entered “movies / games” into the search, the site will receive a request like /search/%E8%E3%F0%FB%2F%F4%E8%EB%FC%EC%FB and this same %2F will be translated first to "/", and the whole request to /search/movies/games and only then the controller will be determined. Accordingly, in my route defined as /search/{query}/{page}, where page restrictions are imposed either absent or consists of numbers, such a request will not fall and the site will return a 404 error.
How to properly escape special characters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antelle, 2010-12-02
@Yavanosta

Add an asterisk to the rule: And there will be no 404
routes.MapRoute("Search", "Search/{*str}",
new { controller = "Search", action = "Index", str = UrlParameter.Optional });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question