简体   繁体   中英

MVC Controller routing, change the name of controller in url

I've got controller named IHateYou , and got loads of views inside that I can access through typing ...\\IHateYou\\User1 . I need to change the name of controller to Users in url, but the rest stays the same, so the users can still enter it through ...\\Users\\User1 . I've tried adding route, but I could still access it by the prior way.

i think you should add a constraints to your default route

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "IHateYou", action = "Index", id =UrlParameter.Optional },
constraints: new{ controller= "[^IHateYou]" });

default route alway match controller/action/id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM