I want to hide the controller name from URL. I am using the below code.
routes.MapRoute(
name: "Customized",
url: "{action}",
defaults: new { controller = "Home", action = "Default", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Default", id = UrlParameter.Optional }
);
This works perfecly.
but only works when i type
http :// domain/ActionName
otherwise, I still able to see
http :// domainname/controller/action
Is there any way to http ://domain/ActionName even if user tried to type
http :// domainname/controller/action
If you have only one Controller (Home) I guess you can have only one route definition ( assuming all your actions share the same parameter pattern) :
routes.MapRoute(
name: "Customized",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Default", id = UrlParameter.Optional }
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With