问题描述
我想确认一个帐户,但我得到无效的标记。错误。
I'm trying to confirm an account but I'm getting "invalid token." error.
下面就是我想:
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmacaoEmail", "Usuario", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Ativação de Conta", user.GetEmailAtivacao(model.Nome, callbackUrl));
如果我称之为 UserManager.ConfirmEmailAsync
这code后,我可以确认的帐户。不过,如果我打开链接,它的变量callbackUrl内,并尝试通过行动来证实,我得到的错误。
if I call UserManager.ConfirmEmailAsync
after this code, I can confirm the account. However, if I open the link that it's inside the variable callbackUrl and try to confirm through that action, I'm getting the error.
我想这可能是一些与OwinContext,所以我决定打电话 HttpContext.GetOwinContext()GetUserManager< MyCustomUserService>
,但我得到了同样的错误
I thought it could be something with OwinContext, so I've decided to call HttpContext.GetOwinContext().GetUserManager<MyCustomUserService>
but I'm getting the same error.
任何线索?
推荐答案
最有可能是在运输过程中的code是通过浏览器进行修改。尝试在令牌做UrlEn code:
Most likely that the code in transit is modified by browser. Try doing UrlEncode on the token:
var code = await userManager.GenerateEmailConfirmationTokenAsync(userId);
code = System.Web.HttpUtility.UrlEncode(code);
,否则浏览器与特殊符号,可以在令牌present弄乱
Otherwise browser messes with the special symbols that can be present in the token.
这篇关于确认邮件ASPNET身份令牌无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!