相关疑难解决方法(0)

MVC5(VS2012)标识CreateIdentityAsync - 值不能为null

我正在尝试为MVC5站点设置OAuth(在VS2012中).

我正在使用Fluent NHibernate.我已经设置了自己的Userstore并传入一个存储库对象来访问NHibernate会话对象.我将我的商店传递给默认的aspnet usermanager提供程序.这最终适用于本地注册和登录.我不是要设置连接/注册Facebook.

它获得了一个成功的帐户.在用户表中添加用户,在登录表中添加记录然后爆炸.我没有在用户存储中实现声明,或者在用户对象中放置声明集合.(不确定这是否真的需要,我正在剥离所有可能出错的东西以找到问题的根源).

爆炸的线是(在账户控制器中):

var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);            
Run Code Online (Sandbox Code Playgroud)

在这种方法中:

private async Task SignInAsync(IdentityUser user, bool isPersistent)
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪的结束

[ArgumentNullException: Value cannot be null.
Parameter name: value]
   System.Security.Claims.Claim..ctor(String type, String value, String valueType, String issuer, String originalIssuer, ClaimsIdentity subject, String propertyKey, String propertyValue) +14108789
   System.Security.Claims.Claim..ctor(String type, String value, String valueType) +62
   Microsoft.AspNet.Identity.<CreateAsync>d__0.MoveNext() +481
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +49
   Web.Controllers.<SignInAsync>d__42.MoveNext() in d:\Google Drive\Development\GoalManagement\Web\Controllers\AccountController.cs:375
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
   Web.Controllers.<ExternalLoginConfirmation>d__35.MoveNext() in d:\Google Drive\Development\GoalManagement\Web\Controllers\AccountController.cs:311
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144 …
Run Code Online (Sandbox Code Playgroud)

asp.net identity claims-based-identity asp.net-mvc-5 asp.net-identity

34
推荐指数
4
解决办法
2万
查看次数

SignInManager 在尝试登录时抛出 null

我正在实施 asp.net 身份。我已经用int主键而不是默认的String. 我按照以下文章这样做:文章

抱歉所有的代码,但是我已经被这个愚蠢的错误困住了一段时间,所以我宁愿提供更多的信息而不是更少的信息。

我有以下课程:

public class FskUser : IdentityUser<int, FskUserLogin, FskUserRole, FskUserClaim>
{
    ...
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<FskUser, int> manager)
    {
                    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的自定义登录管理器

  public class FskSignInManager : SignInManager<FskUser,int>
{
    public FskSignInManager(FskUserManager userManager, IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }

    public override Task<ClaimsIdentity> CreateUserIdentityAsync(FskUser user)
    {
        return user.GenerateUserIdentityAsync((FskUserManager)UserManager); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc-4 owin asp.net-identity-2

7
推荐指数
1
解决办法
4704
查看次数