2017-02-28 56 views
0

你好我試圖在用戶進行登錄到他/她的儀表板如何自定義路線配置,如果用戶已經登錄ASP MVC 5

我知道該怎麼做在家庭控制器重定向用戶到特定的控制器,但登錄後的用戶永遠不能進入主頁/索引。

下面是我在RouteConfig.cs計劃:

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     if(user is logged in already) 
     { 
      routes.MapRoute(
       name: "LoggedIn", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Manage", action = "Dashboard", id = UrlParameter.Optional } 
      ); 
     } 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
} 

請幫幫忙!

更新!

對不清楚。用戶登錄後,我讓他們去管理/儀表板。

所以這就是這樣的情況:如果一個用戶登錄並使用我的網頁,並關閉網頁瀏覽器(不註銷),那麼當用戶打開網頁瀏覽器來到我的網站時,他會自動重定向到管理/儀表板。

現在,當用戶關閉網絡瀏覽器並從頭開始打開網頁時,他總是看到Home/Index。

我想登錄誰關閉Web瀏覽器用戶,回來我的網站(仍然登錄)自動轉入由他們的儀表盤做路由東西..在家庭控制器

+0

你綁兩個缺省路由設置? – Usman

+0

登錄後用戶轉到主頁/索引時會發生什麼? – Usman

+0

我認爲一條默認路線可以。所以當用戶登錄時,默認路由應該轉到儀表板。 –

回答

0
Public ActionResult Index() 
{ 
    If(user is logged in already) 
    { 
    Return RedirectToAction("dashboard","manage"); 
    } 
// code something 
} 

寫RedirecttoAction方法索引操作導航到其他網頁。

+0

不,這是不是我想要的。我想要當用戶打開我的網站,然後去他的儀表板。但他也可以稍後回到主頁/索引。你的答案是強迫用戶總是去他的儀表板,永遠不能去首頁/索引。 –

0

您可以添加一個參數到家庭行爲。

Public ActionResult Index(string show) 
{ 
    if (User.Identity.IsAuthenticated && String.IsNullOrEmpty(show)) 
    { 
     Return RedirectToAction("Dashboard","Manage"); 
    } 
    else 
    { 
     Return View(); 
    } 
} 

,以及要對儀表盤的主頁URL有一個鏈接,去到/ home /指數?秀=真

相關問題