Donate

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class

In the Account Controller Register action (public ActionResult Register(RegisterModel model)) I have a code below that by default assign a Customer Role to a new user during registration. In my database, the defined roles are "Administrator" and "Customer". However, the code below generates exception as stated on the title post.
SimpleRoleProvider role = new SimpleRoleProvider();
role.AddUsersToRoles(new string[] { model.UserName }, new string[] { "Customer" });
The solution would be to use the Role class defined in System.Web.Security namespace instead of SimpleRoleProvider:
Roles.AddUserToRole(model.UserName, "Customer");
Reference: Perils of MVC 4 AccountController
Cheers! :)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations