任務47:Identity MVC:ReturnUrl實現

任務47:Identity MVC:ReturnUrl實現

 

 

在最上面加一個私有的方法async

 

 

 

登錄也加上returnUrl

 

Login的post方法。加入returnUrl的參數post

 

 

 

登錄界面也須要加上測試

asp-route-returnUrl="@ViewBag["ReturnUrl"]"spa

 

退出的代碼進行修改,不然是沒法退出的

 

 

   public async Task<IActionResult> LoginOut()
        {
            //HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
            await _signInManager.SignOutAsync();

            return RedirectToAction("Index", "Home");
        }

 

 

運行程序測試

登錄和註冊都寫完了3d

 

修改好退出的代碼之後,就能夠正常的的退出了。code

代碼修正

 

 

輸入地址:blog

https://localhost:44347/adminit

會自動跳轉到:io

https://localhost:44347/Account/Login?ReturnUrl=%2Fadminclass

 

 

輸入帳號和密碼進行登錄

登錄後,就根據returnUrl跳轉到了admin的頁面

相關文章
相關標籤/搜索