I am using Asp.net Mvc 5 with C#.
I want to disable default routing in my project. My map routes like;
routes.MapRoute(name: "News",
url: "haberler",
defaults: new { controller = "News", action = "Index"});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
When a user visits my website’s news page, it’s like;
www.domain.com/haberler
But also the user can visit the news page as below;
www.domain.com/news
I want to remove that "/news"
or direct to seo-friendly url like; “/haberler”
So how can I disable default routing (Controller-Name-Convension)
routing?
3
Answers
Instead of removing the “default” route, you can add a controller constraint to it
Like this,
/news
will return 404 Not Found.www.domain.com/news
will not match in any of your routes hence it will throw an error.Try removing with this
Hope this will helps you.