我有一個控制器,它有一個名爲RedirectLogin的操作,它基本上將TempData var設置爲重定向到登錄完成時。asp mvc RedirectToRoute將當前操作添加到重定向
在此之後,它只是簡單地調用:
return RedirectToRoute("Login");
然而,當它重定向,它進入/登錄/ RedirectLogin - 它是在調用動作的名稱,套結出於某種原因。我認爲它應該只是返回默認值,而不是添加動作,特別是不屬於目標控制器的動作。
如果我稱之爲:
return RedirectToRoute("Login", new { action = "Index" });
然後正確地使路徑/登錄,但同樣,不應該是做在默認情況下,沒有額外的位?
我有一個稍微不標準的路由設置。基本上我爲我的客戶創建虛擬子文件夾,所以www.domain.com/clienturl,但我仍然希望www.domain.com/join或www.domain.com/about重定向到非客戶端數據。我通過直接在路徑中添加控制器的名稱來完成此操作,並在名爲Landing的更通用的控制器之前添加它。難道這是問題,或者是有沒有更好的辦法做到這一點:)
// Root paths
routes.MapRoute("About", "about", new { controller = "Home", action = "About" });
routes.MapRoute("Info", "info", new { controller = "Home", action = "Info" });
routes.MapRoute("Privacy", "privacy", new { controller = "Home", action = "Privacy" });
routes.MapRoute("Terms", "terms", new { controller = "Home", action = "Terms" });
// Root controllers
routes.MapRoute("Join", "join/{action}/{id}", new { controller = "join", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("Login", "login/{action}/{id}", new { controller = "login", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("Account", "account/{action}/{id}", new { controller = "account", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("Goodbye", "goodbye/{action}/{id}", new { controller = "goodbye", action = "Index", id = UrlParameter.Optional });
// Organization
routes.MapRoute("Landing", "{organization}/{controller}/{action}/{id}", new { controller = "Landing", action = "Index", id = UrlParameter.Optional });
// Default
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });