Kevin Pang
Kevin Pang

Reputation: 41452

ASP.NET MVC route question

I have two routes I want mapped in my ASP.NET MVC application

  1. /User/Login
  2. /User/{userid}/{username}/{action} (e.g. /User/1/blah/profile)

Here are the routes I've defined:

    routes.MapRoute(
        "Profile",
        "Users/{userID}/{username}/{action}",
        new { controller = "Users", action = "Profile" }
    );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = "" }
    );

This works great so far in most instances. The following URLs work from my home page:

<%= Html.ActionLink((UsersController x) => x.Login(), "Login") %>
<%= Html.ActionLink((UsersController x) => x.Profile(1, "blah") %>

These map to (respectfully):

/Users/Login /Users/1/blah

However, once I've navigated to /Users/1/blah, the login url immediately turns to /Users/1/blah/login. Any idea how to fix this?

Upvotes: 1

Views: 571

Answers (2)

Chris James
Chris James

Reputation: 11731

You want to use <%=Html.RouteLink%>

This is very similar to the problem I had which you can view here

Upvotes: 1

E Rolnicki
E Rolnicki

Reputation: 1717

is your route hitting an Authorize filter? Is there a requirement to be logged in to view the /Users/1/blah page? (ie. is there an [Authorize] attribute on the UsersController class, or on the Profile Action?)

well then, if it is not an Authorize filter, I highly suggest you implement this Routing Debugger Tool into your project.

Upvotes: 0

Related Questions