1- Login.cshtml

<h3>Login</h3>
@model MvcCookieAuthSample.ViewModel.LoginViewModel
<div class="row">
<div class="col-md-4">
<form method="post" asp-controller="Account" asp-action="Login"> <hr /> <div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
</div> <div class="form-group">
<label asp-for="Password"></label>
<input asp-for="Password" class="form-control" />
</div> <button type="submit" class="btn btn-default">Login</button>
</form>
</div>
</div>

2-登陆具体方法

 [HttpPost]
public async Task<IActionResult> Login(ViewModel.LoginViewModel loginModel)
{
var findUser =await _userManager.FindByEmailAsync(loginModel.Email);
if (findUser == null)
{
return BadRequest();
}
await _signInManager.SignInAsync(findUser, true);
return RedirectToAction("Index", "Admin");
} public IActionResult LoginOut()
{
_signInManager.SignOutAsync();
return RedirectToAction("Index", "Home");
}

3-在修改公用模板

  @if (User.Identity.IsAuthenticated)
{
<li> <a title="Welcome" asp-controller="Admin" asp-action="Index"> @User.Identity.Name</a> </li>
<li><a asp-controller="Account" asp-action="LoginOut">退出</a></li> }
else
{
<li><a asp-area="" asp-controller="Account" asp-action="Register">注册</a></li>
<li><a asp-area="" asp-controller="Account" asp-action="Login">登陆</a></li>
}

最新文章

  1. 布局TextView和EditText区别,layout_width和lay_weight区别--Android Studio
  2. SSH实战 &#183; JAVA发送邮件相关
  3. SILVERLIGHT 应急卫生模拟演练项目之childwindow
  4. 强势回归,Linux blk用实力证明自己并不弱!
  5. HibernateTemplate的一些常用方法总结
  6. [转]svn常用命令
  7. Cheatsheet: 2015 12.01 ~ 12.31
  8. shell 脚本实战笔记(1)--source/fork/exec的区别
  9. URAL 1072 Routing(最短路)
  10. 3. c的输入输出
  11. 【转】Select模型原理
  12. MyBatis学习笔记之resultMap
  13. RabbitMQ安装和配置
  14. python内存管理
  15. chm 字体修改
  16. 《python基础教程》笔记之 抽象
  17. ①bootstrap引入
  18. 学习 JavaScript (八) 引用类型之 Object
  19. Source-Based XSS Test Cases
  20. Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Unable to compile class for JSP] with root cause java.lang.IllegalArgumentException: Page directive: inval

热门文章

  1. Sendip 命令行发包工具,支持IP、TCP、UDP等
  2. 记录一次 sql在数据库可以查到 mybatis代码查不到的问题
  3. Oracle权限相关查询
  4. python入门19 异常及异常处理 异常捕获
  5. MySQL:数据库入门篇5
  6. Spring Boot 推荐的基础 POM 文件
  7. python-实现登录接口
  8. HTTP请求方式中8种请求方法(简单介绍)
  9. 【luogu P4137 Rmq Problem / mex】 题解
  10. HDU 2859 Phalanx(对称矩阵 经典dp样例)