문제
나는 많은 게시물을 읽었고, 나는 나의 신비를 보지 못한다.
어떤 몸이 나를 도와 줄 수 있습니까?
내 Global.asax가 있습니다
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
내가 사용할 때
<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>
이 URL을 받았습니다
http : // localhost : 8458/accound/editprofile? username = cboivin
URL을 직접 호출하려고한다면http : // localhost : 8458/accound/editprofile/cboivin
일하지 않음 ...
내 AccountController에는 내 메소드가 있습니다
public ActionResult EditProfile(string username)
{
return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
}
나는 내 실수가 어디에 있는지 모른다. 어떤 몸이 나를 도울 수 있습니까? 감사.
해결책
경로는 상단 아래로 읽히고 "모든 캐치"일반 경로는 마지막이어야합니다.
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
다른 팁
제거 시도 :
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
그리고 더 일반적인 경로는 라우팅 테이블의 맨 아래에 있어야하며, 더 구체적인 경로는 위에 올라야합니다.
제휴하지 않습니다 StackOverflow