在Asp.Net Web API项目中使用身份重置密码时,我遇到此“没有IUserTokenProvider”的问题

AuthContext.cs

using microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using system.web;

namespace MyProject.WebAPI.Identity
{
    public class AuthContext : IdentityDbContext<IdentityUser>
    {
        public AuthContext() : base("AuthContext")
        { }
    }
}

AuthRepository.cs

using microsoft.AspNet.Identity;
using microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Threading.Tasks;

namespace MyProject.WebAPI.Identity
{
    public class AuthRepository : IDisposable
    {
        private AuthContext _ctx;

        private UserManager<IdentityUser> _userManager;

        public AuthRepository()
        {
            _ctx = new AuthContext();
            _userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(_ctx));

        }

        public async Task<string> GeneratePasswordResetTokenAsync(string userid)
        {
            return await _userManager.GeneratePasswordResetTokenAsync(userid);
        }

        public async Task<IdentityUser> FindByNameAsync(string username)
        {
            return await _userManager.FindByNameAsync(username);
        }

        public async Task<bool> IsEmailConfirmedAsync(string userId)
        {
            return await _userManager.IsEmailConfirmedAsync(userId);
        }

        public void Dispose()
        {
            _ctx.Dispose();
            _userManager.Dispose();

        }
    }
}

accountController.cs

在帐户控制器中,交易是根据通过移动应用程序发送到服务的信息执行的。 在ForgotPassword方法忘记密码中使用GeneratePasswordResetTokenAsync方法创建令牌时,未注册IUserTokenProvider。我该怎么解决。其他身份验证方法可以正常工作。

using MyProject.WebAPI.Identity;
using MyProject.WebAPI.Models;
using MyProject.WebAPI.Models.Dto;
using MyProject.WebAPI.ValidationRules.FluentApi;
using MyProjectCore;
using FluentValidation.Results;
using microsoft.AspNet.Identity;
using microsoft.AspNet.Identity.EntityFramework;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using system.security.Claims;
using System.Threading.Tasks;
using system.web;
using system.web.Http;

namespace MyProject.WebAPI.Controllers
{
    [ClaimsAuthorization]
    public class accountController : ApiController
    {
        private AuthRepository _repo = null;

        public accountController()
        {
            _repo = new AuthRepository();
        }

        [HttpPost]
        public async Task<HttpResponseMessage> ForgotPassword(ForgotPasswordViewModel model)
        {   
            ResultDataDto result = new ResultDataDto();

            if (ModelState.IsValid)
            {
                var user = await _repo.FindByNameAsync(model.Email);
                if (user == null)
                {
                    result.isSuccess = false;
                    result.statusCode = (int)HttpStatusCode.NotFound;
                    result.errorMessage = new List<string> { "Bu mail adresi ile kullanıcı bulunamadı!" };
                    return Request.CreateResponse(HttpStatusCode.NotFound,result);
                }

                if (await _repo.IsEmailConfirmedAsync(user.Id) == false)
                {
                    result.isSuccess = true;
                    result.statusCode = (int)HttpStatusCode.OK;
                    result.errorMessage = new List<string> { "Şifrenizi güncelleyebilmeniz için,mail adresinize gelen aktivasyon linki ile hesabınızı aktifleştirmeniz gerekmektedir!" };
                    return Request.CreateResponse(HttpStatusCode.OK,result);
                }

                string code = await _repo.GeneratePasswordResetTokenAsync(user.Id);

                result.isSuccess = true;
                result.statusCode = (int)HttpStatusCode.OK;
                result.data = new { email = model.Email,code = code };

                return Request.CreateResponse(HttpStatusCode.OK,result);       
            }
            else
            {
                result.isSuccess = false;
                result.statusCode = (int)HttpStatusCode.BadRequest;
                result.errorMessage = new List<string> { "Şifrenizi yenileyebilmeniz için mail adresinizi girmeniz gerekmektedir!" };
                return Request.CreateResponse(HttpStatusCode.BadRequest,result);
            }    
        }
}
}
i_michael 回答:在Asp.Net Web API项目中使用身份重置密码时,我遇到此“没有IUserTokenProvider”的问题

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3117799.html

大家都在问