Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At the line:</p> <pre><code>if (WebSecurity.UserExists(model.UserName)) roles.AddUserToRole("admin1", "Admin") </code></pre> <p>Did you set "admin1" hardcoded on purpous? Because if you did this might be the reason you are getting foreign key errors as this combination might already be in the database.</p> <p>So changing this to:</p> <pre><code>if (WebSecurity.UserExists(model.UserName)) roles.AddUserToRole(model.Username, "Admin") </code></pre> <p>Should resolve the problem.</p> <p>Next to that from the context CreateUserByAdmin i'm not really sure what you are trying to do. Are you trying to add a user to the DB by an administrator, or a user that has to become an administrator?</p> <p><strong>Update</strong></p> <p>Can you change your code like this? try {</p> <pre><code> var model = register ?? new RegisterModel(); if (!WebSecurity.UserExists(model.UserName)) { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); } if (Roles.RoleExists(role)) { Roles.AddUserToRole(model.UserName, role); } else ModelState.AddModelError("NoRole", "Please select a role."); var roles = Roles.GetAllRoles().ToList(); ViewBag.DeliveryArea = new SelectList(roles.Select(x =&gt; new { Value = x, Text = x }), "Value", "Text"); return View(); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", AccountController.ErrorCodeToString(e.StatusCode)); } return View(); </code></pre> <p>This way we at least exclude fk errors on users already existing. If this fails to work can you please include the entire Exception stack?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload