Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with Areas and root Area #4

Open
mike-ne opened this issue Feb 27, 2014 · 1 comment
Open

Use with Areas and root Area #4

mike-ne opened this issue Feb 27, 2014 · 1 comment

Comments

@mike-ne
Copy link

mike-ne commented Feb 27, 2014

I am attempting to use your LowercaseDashedRouting utility to make our URLs more SEO friendly. I am struggling with the configuration of the routes. We have a site that uses Areas, but also has a "root Area" (controllers and views that are not in an Area). We are using ASP.NET MVC 4 with Razor.

Here is how I have set up the "root Area" (/App_Start/RouteConfig.cs):

LowercaseDashedRoute defaultRoute = new LowercaseDashedRoute(
    url: "{controller}/{action}/{id}",
    defaults: new RouteValueDictionary(new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
    constraints: null,
    dataTokens: new RouteValueDictionary(new { namespaces = new[] { "ReiWeb.Controllers" } }),
    routeHandler: new DashedRouteHandler()
);
routes.Add(defaultRoute);

(Note: I need to specify "namespaces" here because we have Home controllers for each area including the "root area")

Here is how I have set up each of our Areas (this is for our StudentPortal area at /Areas/StudentPortal/StudentPortalAreaRegistration.cs):

LowercaseDashedRoute areaDefaultRoute = new LowercaseDashedRoute(
    url: "StudentPortal/{controller}/{action}/{id}",
    defaults: new RouteValueDictionary(new { action = "Index", id = UrlParameter.Optional }),
    routeHandler: new DashedRouteHandler()
);
context.Routes.Add("StudentPortal_default", areaDefaultRoute);

If I only set up the route for the "root Area" this works fine. However, as soon as I add the routing configuration for out StudentPortal area all URLs generated with the "@Html.ActionLink" or equivalent methods will contain "student-portal/" at the beginning even if they are not in the student portal. It seems like the student portal route configuration is overriding the configuration for the "root Area". Any idea why this might be happening?

Note that all the links in this site get properly generated when I use the following routes (ie. when I don't use the LowercaseDashedRouting utility):

/App_Start/RouteConfig.cs:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new[] { "ReiWeb.Controllers" }
);

/Areas/StudentPortal/StudentPortalAreaRegistration.cs

context.MapRoute(
    "StudentPortal_default",
    "StudentPortal/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional }
);

Thanks for your help.

@salarcode
Copy link
Contributor

The bug is fixed here:
https://github.com/salarkh/lowercase-dashed-route

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants