UserManager保持抛出System.ArgumentNullException

Izz*_*zzy 9 c# asp.net entity-framework owin asp.net-identity-2

我想实现的标准IdAspNetUsers,从nvarcharint.我已经设法让那一方工作了.但是我的问题是当我尝试登录时,我不断从UserManager课堂上收到错误.

我的代码如下:

public class UserManager : UserManager<ApplicationUser, int>
{
    public UserManager(IUserStore<ApplicationUser, int> store) 
    : base(store) 
{ 
}
Run Code Online (Sandbox Code Playgroud)

在我登录的页面上

if (IsValid)
        {
            // Validate the user password
            var manager = Context.GetOwinContext().GetUserManager<UserManager>();
            var user = manager.Find(UserName.Text, Password.Text); //This line throws the error
            if (user != null)
            {
                IdentityHelper.SignIn(manager, user, isPersistent: false);
                Response.Redirect("~/Home.aspx");                }
            else
            {
                FailureText.Text = "Invalid username or password.";
                ErrorMessage.Visible = true;
            }
        }
Run Code Online (Sandbox Code Playgroud)

我一直得到的错误是System.ArgumentNullException:Value不能为null.参数名称:manager.还有其他人遇到过这个问题吗?在此先感谢您的帮助

堆栈跟踪

[ArgumentNullException: Value cannot be null.
Parameter name: manager]
Microsoft.AspNet.Identity.UserManagerExtensions.Find(UserManager`2 manager, String userName, String password) +221
Account_Login.LogIn(Object sender, EventArgs e) in Login.aspx.cs:17
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.<ProcessRequestMainAsync>d__14.MoveNext() +5226
Run Code Online (Sandbox Code Playgroud)

Ser*_*diy 15

确保UserManager在您的OWIN上下文中注册.你应该在Startup课堂上有类似的东西:

app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
Run Code Online (Sandbox Code Playgroud)

还要确保将[assembly: OwinStartup(typeof(YourNamespace.Startup))]属性应用于Web装配.