简体   繁体   中英

Logout automatically in MVC5 using identity

I am using MVC5 identity with Entity Framework DB First.I am completely new to MVC5 identity.

I want to use register form which will be registered by the admin for the users. So, admin should not be logged out, also want to create new user. Any idea of using new register form without using RegisterViewModel and account controller..

Want to add the values in AspNetUser table as well as my own table related to users.

I tried in different form it saves the record in AspNetUser table, but it automatically logs out or it just hangs when I try to save in another table with the same record in same function, sometimes it will stuck,it will not show error or any meesage

 var user = new ApplicationUser() { UserName = model.UserName };
 var result = await UserManager.CreateAsync(user, model.Password);
 if (result.Succeeded){
model.userid=user.Id;
db.Users.Add(modal);
db.SaveChanges();
}

I did not use this line:

await SignInAsync(user, isPersistent: false);

currently I cant provide full code, just consider the above lines its similar... Records are not added in User table, but it is added correctly in AspNetUser table.

Is the method wrong?

There is a lot that can go wrong in the code that you are not showing. I trust you have some implementation of IUserStore and IRoleStore and are creating it in the Startup.ConfigureAuth method? You don't necessarily have to use the model, but you have to create a SignInManager, UserManager, and RoleManager and place them in the context or you may have problems.

You may want to look at the custom providers to get an idea of what is expected:

Overview of Custom Storage Providers for AspNet Identity

这是因为,我提交的表单没有.cshtml页中的html开始表单,因此它从布局的登录部分视图页面提交了注销开始表单

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM