c# - How to to make /Home/Index redirect to / -


given default route, either of following urls navigate index method of home controller:

 1. http://localhost  2. http://localhost/home/index 

i want make when user navigates localhost/home/index redirected localhost or presented not found result. `

my aim disable home/index address without removing default route (as useful in other places.

i want achieve because have hard-coded relative urls in js work when relative localhost.

the default route way, looks this:

routes.maproute(     "default",     "{controller}/{action}/{id}",     new { controller = "home", action = "index", id = urlparameter.optional } ); 

in route file, add this:

 routes.maproute(          name: "homeredirect",          url: "home/index",          defaults: new { controller = "home", action = "index", redirect = true }  ); 

in homecontroller

   public actionresult index(bool? redirect)     {         if (redirect.hasvalue && redirect.value)             return redirecttoactionpermanent("index", new { redirect = null object });         return view();     } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -