ASP.NET MVC routing question
I have two routes that I want to display in my ASP.NET MVC application
- / User / Login
- / User / {userid} / {username} / {action} (for example, / User / 1 / blah / profile)
Here are the routes I have 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 in most cases. The following urls work on my home page:
<%= Html.ActionLink((UsersController x) => x.Login(), "Login") %>
<%= Html.ActionLink((UsersController x) => x.Profile(1, "blah") %>
These cards (respectfully):
/ Users / Login / Users / 1 / bla
However, as soon as I navigated to / Users / 1 / blah, the login url immediately switches to / Users / 1 / blah / login. Any idea how to fix this?
+1
source to share
2 answers
Does your route fall into an authorized filter? Is there a need to be logged in to view the page / Users / 1 / blah? (i.e. is there an [Authorize] attribute in the UsersController class or in the Profile action?)
well then, if it is not an authorization filter, I highly recommend that you implement this "Routing Debug Tool" into your project.
0
source to share