Dummy Dummy - 2 months ago 74
ASP.NET (C#) Question

Can not sign in using ASP.NET Identity, Value cannot be null.Parameter name: manager

I've this login method when I reach at this point it gives me an error

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


The exception it shows is this


An exception of type 'System.ArgumentNullException' occurred in
Microsoft.AspNet.Identity.Owin.dll but was not handled in user code

Additional information: Value cannot be null.


But here is the main error that it shows


{"Value cannot be null.\r\nParameter name: manager"}


here is the stack trace

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()


This here is my complete login method

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;
}

Answer

The problem was the user I created before extending my OWIN to role based and group based Authorization became null and void so I'd to add this new line every time I create a new user its SecurtyStamp needed to be updated like this

await UserManager.UpdateSecurityStampAsync(user.Id);

Hope this helps any one

Comments