URL Catch All

I am wondering if there is anyway to reach the url, for example http://www.mycompany.com/user in MVC I tried to use catch but could not get the user so that I could look up.

thanks

+3
source share
1 answer

Something like that?

routes.MapRoute("User",
    "{UserName}",
    new { Controller = "User", Action = "Index", UserName = "" });

UPDATED:

add this restriction to the User route:

routes.MapRoute("User",
    "{UserName}",
    new { Controller = "User", Action = "Index", UserName = "" },
    new { UserName = @"(\w|-)+" }
);

or add this route:

routes.MapRoute("Home",
    String.Empty,
    new { Controller = "Home", Action = "Index", Id = "" }
);
+1
source

Source: https://habr.com/ru/post/1713173/


All Articles