首页 文章

身份核心主键作为Int无法使用SignInManager

提问于
浏览
0

我想要做的是以下内容:

使用Identity Core设置登录/注销,主键为Int . 我按照ASP.NET核心文档中的以下文章:Configure Identity primary keys data type . (他们使用GUID 's but the idea is the same). The setup is quite succesfull, the ID'是整数,数据库正在填充 .

但是,当我尝试使用内置的 SignInManager<ApplicationUser> 登录并调用该方法时

var result = await _signInManager.PasswordSignInAsync(Username,Password, RememberMe, lockoutOnFailure: false);

我收到以下错误:

System.ArgumentNullException:值不能为null . 参数名称:value

我确定SecurityTimeStamp已填满,并且服务已添加到Startup.cs中

services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<ApplicationDbContext, int>()
            .AddDefaultTokenProviders();

我的课程:

ApplicationUser

public class ApplicationUser : IdentityUser<int>
{
}

ApplicationRole

public class ApplicationRole : IdentityRole<int>
{
}

ApplicationDbContext

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>
        {
            public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
                : base(options)
            {
            }
    }

堆栈跟踪

System.ArgumentNullException:值不能为null . 参数名称:System.Security.Claims.Claim中System.Security.Claims.Claim..ctor(String type,String value,String valueType,String issuer,String originalIssuer,ClaimsIdentity subject,String propertyKey,String propertyValue)的值 . Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2中的ctor(字符串类型,字符串值) . <CreateAsync> d__13.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter Microsoft.AspNetCore.Identity.SignInManager1.d__24.MoveNext()中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的.ThrowForNonSuccess(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束 - - 位于Microsoft.AspNetCore.Identity.SignInManager1的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) . <SignInAsync> d__29 .MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处Microsoft.AspNetCore.Identity.SignInManager1.d__46.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices上的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处Microsoft.AspNetCore.Identity.SignInManager1中的.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) . <PasswordSignInAsync> d__32.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter Microsoft.AspNetCore.Identity.SignInManager1.d__33.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的.ThrowForNonSuccess(任务任务)---栈尾来自抛出异常的先前位置的跟踪---在System.Runtime.CompilerServices.Throw上的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务),System.Runtime.CompilerServices.TaskAwaiter1.GetResult上的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) )在Controllers.AccountController . <Login> d _7.7.MoveNext()在C:\ src \ Controllers \ AccountController.cs中:第64行---从抛出异常的上一个位置的堆栈跟踪结束---在System.Runtime . 位于Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) . <InvokeActionFilterAsync> d__28.MoveNext()---堆栈跟踪结束抛出异常的先前位置---在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker . <InvokeAsync> d__18.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束 - - 位于Microsoft.AspNetCore.Builder.RouterMiddleware的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) . <Invoke> d__4.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1上System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处.d__18.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束--- atMicrosoft.AspNetCore.Authentication.AuthenticationMiddleware1 . <Invoke> d__18.MoveNext()---从抛出异常的上一个位置的堆栈跟踪结束---在System的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) . Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.d__18.MoveNext()中的Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束---在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1 . <Invoke> d__18.MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处(任务任务)在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.d__18.MoveNext()---从先前位置抛出异常的堆栈跟踪结束--- a t Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1 . <Invoke> d__18.MoveNext()---从抛出异常的上一个位置的堆栈跟踪结束---在系统的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.d__18.MoveNext()中的.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)---从抛出异常的上一个位置的堆栈跟踪结束---在Microsoft.AspNetCore.Authentication . AuthenticationMiddleware`1.d__18.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处Microsoft.ApplicationInsights.AspNetCore.ExceptionTrackingMiddleware.d__4.MoveNext()中的(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务),位于Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.d__5.MoveNext()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) . 从抛出异常的先前位置追踪---在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处 . d__6.MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.d__6.MoveNext()---从前一个位置的堆栈跟踪结束被抛出---在System.Runtime.CompilerServices.TaskAw上的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__6.MoveNext()中的aiter.HandleNonSuccessAndDebuggerNotification(任务任务)

1 回答

  • 1

    删除并重新创建数据库......非常明显 .

    //解决了 .

相关问题