2016-09-09 20 views
1

我有這種登錄方式,當我到達在這一點上它給了我一個錯誤不能使用ASP.NET認證標誌,值不能爲null.Parameter名稱:經理

var result = SignInManager.PasswordSignIn(userName, password, false, false); 

例外它顯示是這個

類型「System.ArgumentNullException」的異常出現在 Microsoft.AspNet.Identity.Owin.dll但在用戶代碼中沒有處理

其他信息:值不能爲空。

但這裏的主要錯誤在於它顯示

{ 「值不能爲空\ r \ n參數名:經理」}

這裏是堆棧跟蹤

at Microsoft.AspNet.Identity.Owin.SignInManagerExtensions.PasswordSignIn[TUser,TKey](SignInManager`2 manager, String userName, String password, Boolean isPersistent, Boolean shouldLockout) 
    at MIS.Web.Controllers.PublicController.ValidateUser(String userName, String password) in C:\Users\Jack\Dropbox\Angular 2 Test Environment\MIS BackUp\MIS.Web\MIS.Web\Controllers\PublicController.cs:line 138 
    at lambda_method(Closure , ControllerBase , Object[]) 
    at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) 
    at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() 

這是我的完整登錄方法

public string ValidateUser(string userName, string password) 
     { 
      var userStore = new UserStore<IdentityUser>(); 
      userStore.Context.Database.Connection.ConnectionString = 
       System.Configuration.ConfigurationManager 
       .ConnectionStrings["Test"].ConnectionString; 
      var manager = new UserManager<IdentityUser>(userStore); 


      var user = manager.Find(userName, password); 
      manager.UpdateSecurityStampAsync(user.Id); 



      var result = SignInManager.PasswordSignIn(userName, password, false, false); 
      if (result == SignInStatus.Success) 
       return userName; 

      ModelState.AddModelError("", "Invalid login attempt."); 
      return null; 
     } 
+0

我猜的UserManager是不是在你的owin背景下注冊。確保你有app.CreatePerOwinContext (ApplicationSignInManager.Create);在你的啓動 –

回答

2

問題是我延長我的OWIN基於rolegroup之前創建的基於用戶的Authorization成爲無效的,所以我倒是每次我創建一個新用戶的SecurtyStamp需要等更新時添加這個新行這

await UserManager.UpdateSecurityStampAsync(user.Id); 

希望這有助於任何一個

相關問題