本文介绍了UserManager.IsEmailConfirmedAsync(user.Id)是返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的网站ForgotPassword部分。当我测试它,我有一个断点功能,我可以看到,这条线code是返回false:

 (的await UserManager.IsEmailConfirmedAsync(user.Id)))

我已经验证,在AspNetUsers表EmailConfirmed字段设置为True。为什么会这样仍然可以返回假的?

下面是账户控制器的第一部分,它初始化的UserManager:

  [授权]
公共类的AccountController:控制器
{
    私人ApplicationSignInManager _signInManager;
    私人ApplicationUserManager _userManager;    公众的AccountController()
    {
    }    公众的AccountController(ApplicationUserManager的UserManager,ApplicationSignInManager signInManager)
    {
        的UserManager =的UserManager;
        SignInManager = signInManager;
    }    公共ApplicationSignInManager SignInManager
    {
        得到
        {
            返回_signInManager? 。HttpContext.GetOwinContext()获取< ApplicationSignInManager>();
        }
        私订
        {
            _signInManager =价值;
        }
    }    公共ApplicationUserManager的UserManager
    {
        得到
        {
            返回_userManager? 。HttpContext.GetOwinContext()GetUserManager< ApplicationUserManager>();
        }
        私订
        {
            _userManager =价值;
        }
    }

找到请求Owin串在我的Startup.Auth.cs类:

 公共部分类启动
{
    //欲了解更多有关配置验证,请访问http://go.microsoft.com/fwlink/?LinkId=301864
    公共无效ConfigureAuth(IAppBuilder应用程序)
    {
        //配置分贝范围内,用户管理和登入管理器使用每个请求的单个实例
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext< ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext< ApplicationSignInManager>(ApplicationSignInManager.Create);


解决方案

您有可能指向错误的数据库。对于身份的MVC项目的默认模板将有code这样的背景下:

 公共静态ApplicationDbContext的Create()
{
    返回新ApplicationDbContext();
}

这随后被 OwinContext 的方法来创建你的背景下,作为这样的手段,它会从你的网​​络连接字符串所谓的.config 文件 DefaultConnection 。所以,你有两个选择:


  1. 安装连接字符串以指向正确的数据库。

     <添加名称=DefaultConnection
         的connectionString =这里正确的细节
         的providerName =System.Data.SqlClient的/>


  2. 更改创建方法与特定的连接字符串返回上下文:

     公共静态ApplicationDbContext的Create()
    {
        返回新ApplicationDbContext(NameOfConnectionStringHere);
    }


I am working on the ForgotPassword section of my site. When I test it I have a breakpoint in the function and I can see that this line of code is returning false:

(await UserManager.IsEmailConfirmedAsync(user.Id)))

I have verified that EmailConfirmed field in the AspNetUsers table is set to True. Why would this still be returning false?

Here is the first part of the Account Controller where it initializes the UserManager:

[Authorize]
public class AccountController : Controller
{
    private ApplicationSignInManager _signInManager;
    private ApplicationUserManager _userManager;

    public AccountController()
    {
    }

    public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
    {
        UserManager = userManager;
        SignInManager = signInManager;
    }

    public ApplicationSignInManager SignInManager
    {
        get
        {
            return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
        }
        private set 
        { 
            _signInManager = value; 
        }
    }

    public ApplicationUserManager UserManager
    {
        get
        {
            return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
        }
        private set
        {
            _userManager = value;
        }
    }

Found the requested Owin string in my Startup.Auth.cs class:

public partial class Startup
{
    // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
    public void ConfigureAuth(IAppBuilder app)
    {
        // Configure the db context, user manager and signin manager to use a single instance per request
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
解决方案

You are likely pointing to the wrong database. The default templates for an MVC project with Identity will have code like this in the context:

public static ApplicationDbContext Create()
{
    return new ApplicationDbContext();
}

This is then used by OwinContext as the method to create your context, and as such means that it will take the connection string from your web.config file called DefaultConnection. So you have 2 choices:

  1. Fix the connection string to point to the correct database.

    <add name="DefaultConnection" 
         connectionString="correct details here" 
         providerName="System.Data.SqlClient" />
    

  2. Change the create method to return the context with a specific connection string:

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext("NameOfConnectionStringHere");
    }
    

这篇关于UserManager.IsEmailConfirmedAsync(user.Id)是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 06:12