1

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?

Kevin Pang
  • 41,172
  • 38
  • 121
  • 173

2 Answers2

1

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

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

Community
  • 1
  • 1
Chris James
  • 11,571
  • 11
  • 61
  • 89
0

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.

E Rolnicki
  • 1,677
  • 2
  • 17
  • 26
  • No, anyone can view this page. I'm not sure what this has to do with the routing though. Or are you just curious? – Kevin Pang Dec 16 '08 at 21:54
  • it sounded as if you were being redirected to a login page when trying to hit a page which would typically be protected by an authorization filter. – E Rolnicki Dec 17 '08 at 16:01