0

I'm trying to remove 'home' form my URL, so in other words:

www.domain.com/home/about/ becomes www.domain.com/aboutus

The problem is, the home is not being removed and I can't work out why. I can see others have identical questions with near identical answers as to mine here on on SO so I am at a loss why this won't work.

My Global.asax is

using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace Company.Ui
{
    // Note: For 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 with parameters
                new { controller = "Home", action = "Index" } // Parameter defaults
            );


            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with 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 I hover over a link and when I click on the link, it still returns www.domain.com\home\aboutus

I'm running this in debug mode in Visual Studio 2012.

I am at a loss, can any one help?

Community
  • 1
  • 1
Dave
  • 8,163
  • 11
  • 67
  • 103

1 Answers1

1

I think you are working with your routes in the wrong place,

from the shown code it seems the registered routes are defined in RouteConfig class

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes); //routes are registered here
}

Try replacing

RouteConfig.RegisterRoutes(RouteTable.Routes);

with

RegisterRoutes(RouteTable.Routes);

or edit in the RouteConfig class

hope this helps.

shakib
  • 5,449
  • 2
  • 30
  • 39
  • You are correct. I created a new MVC4 application which registers the maps in the App_Start folder (by default in VS). I had to copy my code into this file and it's worked. Thank you – Dave May 05 '13 at 06:29