ArgumentNull Exception - UserManager.CreateIdentityAsync

时间:2015-10-18 18:14:01

标签: c# asp.net asp.net-mvc asp.net-identity claims-based-identity

在ASP MVC应用程序中,我使用mongodb数据库作为所有用户数据的存储,例如登录,声明等。 为此我实现了接口并在微内核中注册它们。

现在我在ASP MVC帐户控制器中有以下代码。 当我尝试登录时,userManager找到用户。但是UserManager.CreateIdentityAsync会在下面的StackTrace中引发ArgumentNull异常。我可以看到它表明声明的值为空。但是,用户已经拥有非空值的所有声明。

是否可能存在我可能遗失的索赔?

代码:

   AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

    var user = await UserManager.FindAsync(model.UserName, model.Password);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

if (user != null)
{
    AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = model.RememberMe }, identity);

ExceptionStack:

[ArgumentNullException: Der Wert darf nicht NULL sein. Parametername:value]
System.Security.Claims.Claim..ctor(String type, String value, String valueType,
String issuer, String originalIssuer, ClaimsIdentity subject, String propertyKey,
String propertyValue) +11996035
System.Security.Claims.Claim..ctor(String type, String value) +36   
Microsoft.AspNet.Identity.<CreateAsync>d__0.MoveNext() +1599   
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) +99   
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) +58    
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  +28
GP.CRM.Web.Controllers.<DoLogin>d__10.MoveNext() in 
   D:\dev\crm\CRM\src\Web\GP.CRM.Web\GP.CRM.Web.Api\Controllers\AccountController.cs:58

1 个答案:

答案 0 :(得分:1)

enter image description here在搜索了一整天后才找到它。

SecurityStamp 字段为" null"而不是一个空字符串。不确定这与mongodb有关。因为Null是一个" Null" FieldType而不是字符串字段。但是在设置了至少一个空字符串之后就可以了。