任务47:Identity MVC:ReturnUrl实现

任务47:Identity MVC:ReturnUrl实现

 

 

在最上面加一个私有的方法

 

 

 

登陆也加上returnUrl

 

Login的post方法。加入returnUrl的参数

 

 

 

登陆界面也需要加上

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

 

退出的代码进行修改,否则是无法退出的

 

 

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

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

 

 

运行程序测试

登陆和注册都写完了

 

修改好退出的代码以后,就可以正常的的退出了。

代码修正

 

 

输入地址:

https://localhost:44347/admin

会自动跳转到:

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

 

 

输入账号和密码进行登陆

登陆后,就根据returnUrl跳转到了admin的页面

 

posted @ 2019-03-02 14:07  高山-景行  阅读(405)  评论(0编辑  收藏  举报