OWIN/Identity 2.0 - Alterando pk de string para GUID
-
21-12-2019 - |
Pergunta
Estou tentando alterar o sistema pk da identidade asp.net do banco de dados nvarchar(128) -> uniqueidentifier e no código da string -> Guid.Seguindo isto artigo com base na mudança do pk para um int32, tenho apenas um problema que não consigo resolver.
No meu Startup.Auth.cs
classe eu mudei o seguinte
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()))
}
});
e estou recebendo dois erros que não consigo compreender.A estrutura da Identidade me confunde muito com tantos genéricos.Entendo que está recebendo o tipo de parâmetro errado, mas não tenho ideia de como solucionar o problema.
Erros
Erro 1 O melhor método sobrecarregado corresponde a 'Microsoft.aspnet.Identity.owin.securitystampvalidator.onalidateIdentity (System.timespan, System.func>, System.func)' tem alguns argumentos inválidos
Erro 2 Argumento 2:Não é possível converter de 'Lambda Expression' para 'System.func>'
Alguém pode oferecer uma pequena visão?
Solução
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())))
}
});