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
Post a Comment