密码重置链接使用标识和Web API

时间:2016-06-08 12:43:04

标签: email model-view-controller asp.net-web-api identity

我试图在我的WebApi控制器中创建一个动作来发送带有passwors重置链接的电子邮件。但是当电子邮件到达时,链接网址是" http://Account/ResetPassword/ ........"

请注意,de link中缺少网站网址。我需要像" http://www.domain.com/account/resetpassword/ ........."

这样的东西

这是我的代码。谢谢!

    [System.Web.Http.AllowAnonymous]
    [System.Web.Http.HttpGet]
    [System.Web.Http.Route("ForgotPassword")]
    public async Task<IHttpActionResult> ForgotPassword(string email)
    {
        if (string.IsNullOrWhiteSpace(email))
        {
            ModelState.AddModelError("", "Email is required");
            return BadRequest(ModelState);
        }

        var user = await AppUserManager.FindByNameAsync(email);

        if (user != null)
        {
            string code = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id);

            var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

            urlHelper.Action("ResetPassword", "Account", new RouteValueDictionary(new { userId = user.Id, code }), protocol: Request.RequestUri.Scheme);

            await AppUserManager.SendEmailAsync(user.Id, "Redefinir Senha", "Redefina sua senha clicando <a href=\"" + callbackUrl + "\">aqui</a>");

            return Ok();
        }

        return NotFound();

    }

0 个答案:

没有答案