我试图从数据库nvarchar(128) - > uniqueIdentifier和string - > guid中的代码中更改ASP.NET Identity的PK系统。遵循此“文章基于在将pk改为int32时,我只有一个问题,我似乎无法到处。

在我的Startup.Auth.cs等级中我改变了以下

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {   //error on the line below
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, Guid>(TimeSpan.FromMinutes(20), (manager, user) => user.GenerateUserIdentityAsync(manager), (identity) => Guid.Parse(identity.GetUserId()))
            }
        });  
.

,我得到了两个错误,即我无法理解。身份的结构使我的地狱困扰着这么多的泛型。我理解它说它正在收到错误的参数类型,但我不知道如何纠正问题。

错误

错误1最佳的超载方法匹配 'microsoft.aspnet.identity.owin.securitystampvalidator.onvalidateIdentity(system.timespan, system.func>, system.func)'有 一些无效的参数

错误2参数2:无法转换为'lambda表达式' 'system.func>'

任何人都可以提供一点洞察力吗?

有帮助吗?

解决方案

  app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/_layouts/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, WebUser,Guid>(
                    validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (manager, user) => 
                    user.GenerateUserIdentityAsync(manager), 
                getUserIdCallback:(id)=>(Guid.Parse(id.GetUserId())))

            }
        });        
.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top