asp.net-mvc - asp.net 5,满足某些条件时在控制器中注销
问题描述
遇到某些情况时,我想在控制器中注销,
我的想法是重定向到“/Identity/Account/Logout”
我试过但没用
return RedirectToAction("Logout", "Account");
普通代码是:
public IActionResult Home_Index()
{
var Crm_Account_Data = _context.Crm_Account.Where(x => x.Crm_Email.Equals(User.Identity.Name)).FirstOrDefault();
if (Crm_Account_Data != null)
{
return View();
}
else
{
// Logout
// return RedirectToAction("Logout", "Account");
}
}
解决方案
I would suggest creating two action methods. Login() and Logout() Your Login action would be something like this:
[HttpPost]
public ActionResult Login()
{
if (!IsValidUser)
{
//redirect to login view
}
if (IsValidUser)
{
//executables (perhaps passing a model)
}
return this.RedirectToAction("Index", "Home");
}
推荐阅读
- java - 在不更改默认正文的情况下自定义 Spring Boot 错误响应代码
- vim - Vim 键绑定以调用来自用户的输入的函数
- javascript - POST 401 未经授权
- html - 如何将 CSS 下拉列表与其父 div 右对齐?
- python - 在 pandas 中的数据框中显示和添加列
- python - wav文件计算FFT时遇到的问题
- java - 调用方法以及如何使用它们
- python - 当 stride=2 时,pytorch 和 tensorflow 的 ResNet 模型给出不同的结果
- python - 为什么Timedeltas可以减去但不能添加
- python-3.x - 简单的 python3 脚本 (openCV) 不能从 Bash 脚本运行