1

i am using the default template of the ASP.net identity framework for registering users. the problem is i can't remove any users. i got an error "Default Membership Provider must be specified.". i know that i must specify the default membership provider and then use Membership.Delete(..);to simply delete the user. but the problem is that i can't config the membership default provider . i searched a lot but all of the link recommend to use " ASP.NET Configuration" wizard which i can't find in Web-Form project ! here is the code for creating a user:

var manager = new UserManager();
var user = new ApplicationUser() { UserName = UserName.Text };
IdentityResult result = manager.Create(user, Password.Text);
phadej
  • 11,947
  • 41
  • 78
Mohammad Nej
  • 33
  • 1
  • 7
  • Identity and Membership are two different things. Can you show the snippet where you get your error? Or explain a bit more how you have configured your authentication? – Horizon_Net Jan 21 '15 at 09:59
  • i am just start using asp.net ! i used the code above for creating users ! now just want pice of code to remove a user from DB ! if i can't use Membership so what can i do instead? – Mohammad Nej Jan 21 '15 at 14:09
  • If you have created your application from one of the templates provided by VS2013 you should have ASP.NET Identity automatically configured if you checked the right box at the beginning of the creation wizard. After that the only thing left to do to delete a user is to call the [DeleteAsync](https://msdn.microsoft.com/en-us/library/dn497527(v=vs.108).aspx) method of the UserManager. Keep in mind that Membership and Identity are different. For new projects you should use Identity and with that you shouldn't have something like Membership in your project. – Horizon_Net Jan 21 '15 at 14:16
  • the problem is solved i didn't have 'DeletAsync' method because my identity framework version was 1.0 and this method is added in the 2nd version ! i used a bool to active the account instead of complete removing it ! that sounds fair ! – Mohammad Nej Jan 21 '15 at 14:50
  • http://stackoverflow.com/questions/21506753/how-to-delete-users-that-were-created-with-usermanager-createasync this topice solved the problem! – Mohammad Nej Jan 21 '15 at 14:55

1 Answers1

0

Use

userManager.Delete(user)

MembershipProvider is depricated; wherever you use calls to this class - remove them - they are not going to work as Identity framework and MembershipProvider are incompatible

trailmax
  • 34,305
  • 22
  • 140
  • 234
  • In this case something is wrong with your namespacing - this is part of Identity framework and I have used it before. Try `userManager.DeleteAsync(user)`. Sync-version of this method comes as an extension method from another namespace, but included in the nuget you get with Identity. – trailmax Jan 21 '15 at 14:21
  • it's available in version 2 of identity framework! since i am using version i had to use another approach ! i used a bool variable to deactivate the account instead of removing it! – Mohammad Nej Jan 21 '15 at 14:51
  • Old version is worth mentioning in the question. It is worth upgrading to v2 - a lot of improvements are implemented. – trailmax Jan 21 '15 at 15:05