相关疑难解决方法(0)

668
推荐指数
9
解决办法
65万
查看次数

什么是ASP.NET Identity的IUserSecurityStampStore <TUser>接口?

看看ASP.NET Identity(ASP.NET中的新成员实现),我在实现自己的时遇到了这个界面UserStore:

//Microsoft.AspNet.Identity.Core.dll

namespace Microsoft.AspNet.Identity
{ 
    public interface IUserSecurityStampStore<TUser> :
    {
        // Methods
        Task<string> GetSecurityStampAsync(TUser user);
        Task SetSecurityStampAsync(TUser user, string stamp);
    }
}
Run Code Online (Sandbox Code Playgroud)

IUserSecurityStampStore由默认实现EntityFramework.UserStore<TUser>,实质上获取和设置TUser.SecurityStamp属性.

经过一些挖掘之后,似乎a SecurityStampGuid在关键点新生成的UserManager(例如,更改密码).

因为我在Reflector中检查这段代码,所以我无法真正破译.几乎所有的符号和异步信息都已经过优化.

此外,谷歌也没有太多帮助.

问题是:

  • 什么是SecurityStampASP.NET标识,它用于什么?
  • SecurityStamp创建身份验证cookie时,是否扮演任何角色?
  • 是否有任何需要采取的安全措施或预防措施?例如,不要将此值向下游发送给客户端?

更新(2014年9月16日)

源代码在这里:

asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity

168
推荐指数
3
解决办法
6万
查看次数

确认电子邮件中的aspnet身份无效令牌

我正在尝试确认帐户,但我收到"无效令牌".错误.

这是我正在尝试的:

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));
Run Code Online (Sandbox Code Playgroud)

如果我UserManager.ConfirmEmailAsync在此代码后拨打电话,我可以确认该帐户.但是,如果我打开它在变量callbackUrl中的链接并尝试通过该操作确认,我收到错误.

我认为它可能是OwinContext的东西,所以我决定打电话HttpContext.GetOwinContext().GetUserManager<MyCustomUserService>但是我得到了同样的错误.

有线索吗?

asp.net-mvc-5 asp.net-identity asp.net-identity-2

15
推荐指数
2
解决办法
8399
查看次数

令牌无效.使用UserManager.ConfirmEmailAsync(user.Id,code)验证电子邮件验证码时

我最近将Asp.net身份1.0迁移到了2.0.我正在尝试使用以下方法验证电子邮件验证码.但我得到"无效令牌"错误消息.

public async Task<HttpResponseMessage> ConfirmEmail(string userName, string code)
        {
            ApplicationUser user = UserManager.FindByName(userName);
            var result = await UserManager.ConfirmEmailAsync(user.Id, code);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
Run Code Online (Sandbox Code Playgroud)

使用以下代码生成电子邮件验证令牌(如果我在生成令牌后立即调用ConfirmEmailAsyc,这正常工作).但是当我使用不同的方法调用时会出错

public async Task<HttpResponseMessage> GetEmailConfirmationCode(string userName)
        {
            ApplicationUser user = UserManager.FindByName(userName);
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            //var result = await UserManager.ConfirmEmailAsync(user.Id, code);
            return Request.CreateResponse(HttpStatusCode.OK, code);
        }
Run Code Online (Sandbox Code Playgroud)

请帮忙

asp.net-mvc asp.net-web-api asp.net-identity

12
推荐指数
3
解决办法
1万
查看次数

ASP.NET Identity 2.0随机无效令牌

有时,用户在单击其电子邮件确认链接时会收到无效令牌.我无法弄清楚为什么,这纯粹是随机的.

以下是创建用户的代码:

IdentityResult result = manager.Create(user, "Password134567");
if (result.Succeeded)
{
    var provider = new DpapiDataProtectionProvider("WebApp2015");
    UserManager<User> userManager = new UserManager<User>(new UserStore<User>());
    userManager.UserTokenProvider = new DataProtectorTokenProvider<User>(provider.Create(user.Id));
    manager.UserTokenProvider = new DataProtectorTokenProvider<User>(provider.Create("ConfirmUser"));

    var emailInfo = new Email();

    string code = HttpUtility.UrlEncode(Context.GetOwinContext().GetUserManager<ApplicationUserManager>().GenerateEmailConfirmationToken(user.Id));
    string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);

    if (email.IndexOf("@") != -1)
    {
        if (assignedId == 0)
        {
            lblError.Text = "There was an error adding this user";
            return;
        }
        string emailcontent = emailInfo.GetActivationEmailContent(assignedId, callbackUrl, userRole);
        string subject = emailInfo.Subject;
        if (string.IsNullOrEmpty(subject))
        {
            subject = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-identity-2

6
推荐指数
1
解决办法
2811
查看次数