我创建了ASP.NET Core 2.2应用程序,但是很长时间没有使用它,不幸的是我忘记了 admin 凭据,并且无法访问该应用程序。密码和ID会被散列
有什么办法可以手动添加新管理员?
答案 0 :(得分:0)
您可以尝试生成rest密码令牌,并像下面的代码一样保留密码:
public class HomeController : Controller
{
private readonly UserManager<IdentityUser> _userManager;
public HomeController(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
public async Task<IActionResult> Index()
{
return View();
}
public async Task<IActionResult> RestPassword()
{
var user = await _userManager.FindByEmailAsync("test@outlook.com");
var token = await _userManager.GeneratePasswordResetTokenAsync(user);
var result = await _userManager.ResetPasswordAsync(user, token, "2wsx#EDC");
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}