2016-04-29 86 views
3

我一直在試圖讓我的登錄頁面無法訪問到已經登錄的用戶。他們寧願被重定向到他們的儀表板,除非他們沒有登錄。阻止登錄用戶訪問asp.net中的登錄頁面mvc 5

我已經做了以下,他們都沒有工作。任何人都有解決方案嗎?

// GET: /Account/Login 
    [AllowAnonymous] 
    public ActionResult Login(string returnUrl) 
    { 
     if (Request.IsAuthenticated) 
     { 
      RedirectToAction("Index", "Dashboard"); 
     } 

     ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard"); 
     return View(); 
    } 

這也太

// GET: /Account/Login 
    [AllowAnonymous] 
    public ActionResult Login(string returnUrl) 
    { 
     if (User.Identity.IsAuthenticated) 
     { 
      RedirectToAction("Index", "Dashboard"); 
     }    
     ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard"); 
     return View(); 
    } 

任何指導將不勝感激。謝謝

回答

4

對不起,我剛纔觀察到我省略了應該重定向用戶的線路上的「返回」。

我已經補充說,現在可

這低於

// GET: /Account/Login 
[AllowAnonymous] 
public ActionResult Login(string returnUrl) 
{ 
    if (User.Identity.IsAuthenticated) 
    { 
     return RedirectToAction("Index", "Dashboard"); 
    }    
    ViewBag.ReturnUrl = returnUrl ?? Url.Action("Index","Dashboard"); 
    return View(); 
} 
正確的代碼