OWIN/Identity 2.0 -将pk从字符串更改为GUID

本文关键字:字符串 GUID pk Identity OWIN | 更新日期: 2023-09-27 18:15:55

我试图改变asp.net身份的pk系统从数据库nvarchar(128) ->唯一标识符和代码从字符串-> Guid。在这篇基于将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()))
            }
        });  

,我得到两个错误,我不能理解。Identity的结构让我对这么多泛型感到困惑。我理解它说它正在接收错误的参数类型,但我不知道如何补救这个问题。

错误1最佳重载方法匹配"Microsoft.AspNet.Identity.Owin.SecurityStampValidator.OnValidateIdentity (System.TimeSpan,系统。Func>,System.Func)"一些无效参数

错误2参数2:无法从'lambda表达式'转换为的系统。Func>的

谁能提供一点见解?

OWIN/Identity 2.0 -将pk从字符串更改为GUID

  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())))
            }
        });