gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 22:22:26 25 4
gpt4 key购买 nike

我试图从数据库 nvarchar(128) -> uniqueidentifier 和字符串 -> Guid 的代码中更改 asp.net 身份的 pk 系统。按照这个 article基于将 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 的结构让我对这么多泛型感到困惑。我知道它说它收到了错误的参数类型,但我不知道如何解决这个问题。

错误

Error 1 The best overloaded method match for 'Microsoft.AspNet.Identity.Owin.SecurityStampValidator.OnValidateIdentity(System.TimeSpan, System.Func>, System.Func)' has some invalid arguments

Error 2 Argument 2: cannot convert from 'lambda expression' to '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())))

}
});

关于c# - OWIN/Identity 2.0 - 将 pk 从字符串更改为 GUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25048461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com