无法使用ASP登录.. NET标识,值不能为空.参数名称:manager



我有这个登录方法当我到达这一点时它会给我一个错误

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

它显示的异常是

类型为'System '的异常。参数nullexception '发生在microsoft . asp.net . identity . owin .dll,但未在用户代码中处理

附加信息:值不能为空。

但是这里显示的主要错误是

{"值不能为空。rnParameter name: manager"}

这里是堆栈跟踪

   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:UsersJackDropboxAngular 2 Test EnvironmentMIS BackUpMIS.WebMIS.WebControllersPublicController.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;
        }

问题是我在将OWIN扩展到基于role和基于groupAuthorization之前创建的用户变为无效,因此每次创建新用户时我都会添加这一行,其SecurtyStamp需要像这样更新

await UserManager.UpdateSecurityStampAsync(user.Id);

希望对大家有所帮助

请确保Id和UserName不为空或空!

相关内容

  • 没有找到相关文章

最新更新