c# – UserManager保持抛出一个System.ArgumentNullException
发布时间:2020-12-15 17:51:28 所属栏目:百科 来源:网络整理
导读:我试图将AspNetUsers中的标准Id从nvarchar实现为int.我已经设法让这方面工作.但是我的问题是当我尝试登录时,我不断收到UserManager类的错误. 我的代码如下: public class UserManager : UserManagerApplicationUser,int{ public UserManager(IUserStoreAppl
我试图将AspNetUsers中的标准Id从nvarchar实现为int.我已经设法让这方面工作.但是我的问题是当我尝试登录时,我不断收到UserManager类的错误.
我的代码如下: public class UserManager : UserManager<ApplicationUser,int> { public UserManager(IUserStore<ApplicationUser,int> store) : base(store) { } 在登录页面上我已经有了 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; } } 我不断得到的错误是System.ArgumentNullException:值不能为null. 堆栈跟踪 [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 解决方法
确保您在OWIN上下文中注册了UserManager.你应该在你的启动类中有这样的东西:
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 还要确保您已经将[assembly:OwinStartup(typeof(YourNamespace.Startup))]属性应用于Web程序集. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |