asp.net mvc 4 - Cannot get route to rename URL -
i'm trying remove 'home' form url, in other words:
www.domain.com/home/about/ becomes www.domain.com/aboutus
the problem is, home not being removed , can't work out why. can see others have identical questions near identical answers mine here on on so @ loss why won't work.
my global.asax is
using system.web.http; using system.web.mvc; using system.web.routing; namespace company.ui { // note: instructions on enabling iis6 or iis7 classic mode, // visit http://go.microsoft.com/?linkid=9394801 public class mvcapplication : system.web.httpapplication { protected void application_start() { arearegistration.registerallareas(); webapiconfig.register(globalconfiguration.configuration); filterconfig.registerglobalfilters(globalfilters.filters); routeconfig.registerroutes(routetable.routes); } public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute("removehomeurl", // route name "{action}", // url parameters new { controller = "home", action = "index" } // parameter defaults ); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults ); } } }
my actionlink code is:
@html.actionlink("about us", "aboutus", "home", null, new { @class = "mega" })
when hover on link , when click on link, still returns www.domain.com\home\aboutus
i'm running in debug mode in visual studio 2012.
i @ loss, can 1 help?
i think working routes in wrong place,
from shown code seems registered routes defined in routeconfig
class
protected void application_start() { arearegistration.registerallareas(); webapiconfig.register(globalconfiguration.configuration); filterconfig.registerglobalfilters(globalfilters.filters); routeconfig.registerroutes(routetable.routes); //routes registered here }
try replacing
routeconfig.registerroutes(routetable.routes);
with
registerroutes(routetable.routes);
or edit in routeconfig
class
hope helps.
Comments
Post a Comment