Can't add user to role with SimpleMembership (MySQL)

I'm trying to use SimpleMembership with MySql in a Code First project. This is the initializer I made:

WebSecurity.InitializeDatabaseConnection("MyConnectionStringName", "UserProfile", "UserId", "UserName", false); if (!Roles.RoleExists("Employee")) { Roles.CreateRole("Employee"); } if (!WebSecurity.UserExists("Kurt")) { WebSecurity.CreateUserAndAccount("Kurt", "test"); Roles.AddUserToRole("Kurt", "Employee"); }

The following exception appears by "AddUserToRole":

An exception of type 'System.InvalidOperationException' occurred in MySql.Web.dll but was not handled in user code

Additional information: UserTableName configuration was not initialized.

The user is added to the table "userprofile" (and "webpages_membership") and the role to "webpages_roles". "webpages_usersinroles" is empty.

The providers in Web.config (for SimpleMembership with MySql):

<membership defaultProvider="MySqlSimpleMembershipProvider"> <providers> <clear /> <add name="MySqlSimpleMembershipProvider" type="MySql.Web.Security.MySqlSimpleMembershipProvider,MySql.Web,Version=,Culture=neutral,PublicKeyToken=c5687fc88969c44d" applicationName="/" description="MySQLdefaultapplication" connectionStringName="MyConnectionStringName" userTableName="UserProfile" userIdColumn="UserId" userNameColumn="UserName" autoGenerateTables="True" /> </providers> </membership> <roleManager enabled="true" defaultProvider="MySqlSimpleRoleProvider"> <providers> <clear /> <add name="MySqlSimpleRoleProvider" type="MySql.Web.Security.MySqlSimpleRoleProvider, MySql.Web, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="MyConnectionStringName" applicationName="/" /> </providers> </roleManager>

Does anyone know which configuration isn't right here? It's strange because the other things (creating users and roles) are working fine without exceptions.

Thanks in advance!


I have added the attributes from the membershipprovider to the rolemanager.

<roleManager defaultProvider="MySqlSimpleRoleProvider"> <providers> <clear /> <add name="MySqlSimpleRoleProvider" type="MySql.Web.Security.MySqlSimpleRoleProvider, MySql.Web, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="SamandarService_DB" applicationName="SamandarService" userTableName="UserProfile" userIdColumn="UserId" userNameColumn="Name" /> </providers> </roleManager>

Another exception shows up now:

Cannot add or update a child row: a foreign key constraint fails (ticket.webpages_usersinroles, CONSTRAINT fk_RoleId FOREIGN KEY (RoleId) REFERENCES webpages_roles (RoleId))

The role is correctly added to the roles table, but MySql can't reference it because of a mysterious reason.

How do I fix this issue?

Category:c# Views:2 Time:2019-03-14

Related post

  • How can I offer user generated websites with PHP/MySQL? 2010-09-18

    I am getting started on a new project and I haven't been able to find a pre-packaged solution that will allow me to offer users the opportunity to create an account and use my templates to create their own web page/site that is hosted on my server. I

  • Add User from Admin with Devise in ROR 2012-03-02

    I m new to ROR, I want to add Sign-in and Sign-up in my ROR application to add users with role "Admin" and "Vendor" and for this i m using Devise, which created Sign-In and Sign-up and are working fine. Now i want to create a "Add user" section from

  • How can I add users to my new gitosis project? 2010-08-16

    As a fresh Git user, I tried to install git on a server following this guide: Hosting Git repositories, The Easy (and Secure) Way. For... like 3 days in a row. Here was the problem: I followed that guide exactly. But when I came to the 'Creating new

  • Can not add user with Gitolite 2012-03-09

    I am newby with gitolite. I've install gitolite on a remote server. So I could git-cloning gitolite-admin.git. git clone ssh://[email protected]/gitolite-admin.git I wanted to add user and repo using gitolite.

  • Custom User and Roles with ASP.NET MVC3 2012-02-28

    I have a ASP.NET MVC site with a CAS server set up as the authentication type. I also have a separate database with a Users table and a Roles table (with a User being related to one or more roles). A User is only able to log into the system if the Us

  • JNDI Add Users to Groups with ADS 2010-02-23

    We have been trying to add users to groups using JNDI. Our directory server is Active Directory on Windows 2003. We were able to create users and groups just fine. However, making these users part of any group is a problem. Here is what the code look

  • How can I add a new Table with a Button click event MVC? 2010-02-26

    I have a table with text box asking for Name and Address for reference. If need be, I would like the user to have the ability to add more and not be restricted to just one. How would I add a new table to a form by clicking on my "getMore" button?

  • MS CRM can't add users after database restore 2009-12-10

    We have restored an old ms CRM database over a newer version. But when I try and add users which were already existed in newer version I get an error. If I delete the users from our of active directory and then try to add them to CRM it works fine. I

  • How can I add an MSBuild Import with IVsBuildPropertyStorage? 2010-07-01

    I'm trying to add an Import task to a .csproj file programmatically, but I don't want to use the Microsoft.Build.BuildEngine objects to do this because VS will then pop up warnings about the project file being modified from outside of Visual Studio.

  • DRUPAL - How can I add user ID (UID) to the activation email oder user page? 2011-01-26

    How can I add the value user id (uid) from user db in to the activation email? like : "hi XY your ID is :1234" and I would like to print out the id on the user page. thx --------------Solutions------------- For the E-mails you can do the following: I

  • How can i make Users to login with there gmail, or twitter to my site? 2011-06-06

    I have created my project in Symfony(PHP framework) with Propel as ORM. I am using sfGuard Plugin for login/authentication purpose. But our client wants the user to login with there Gmail, Twitter or Facebook account. just like in Stackoverflow, we c

  • Can't add user to gitolite repository 2011-11-15

    I use gitolite script to create projects (repos) and add users. I have already 3 users - 2 are developers, 1 is for jenkins. They have access via ssh (simply generated RSA keys for each one and added them to gitolite keydir, and added users to gitoli

  • How can Windows Phone Users assist Microsoft with Cortana feedback? 2013-04-09

    How can a Microsoftian Windows Phone 8; Nokia Lumia 521 (or any Windows Mobile OS) user, assist Microsoft with feedback with the Cortana Digital Assistant? I downloaded the Developers Update and I am currently enjoying Cortanas assistance, but I had

  • new domain: The requested account name is already in use error. can't add users 2013-12-13

    The requested account name is already in use or was used in the past and has not been through the required waiting period to re-use. I have the same problem. I added my existing domain today and now I can;t add a single user account. I won;t list the

  • Can not add user in Windows 8 Pro x64 2014-10-09

    The User in PC Settings is completely missing, also missing is Windows Update. In the secpol.msc, instead of text I get options like @appinfo.dll,-200 and @wsecedit.dll,-59001 under Local Policies, then Security Options. Some options are missing in t

  • how can i add people to chat with them on messaging/online (IM) 2013-09-04

    hello every one. a few month ago i invite my friend in outlook/people/manage/invite to chat but recently when i go there there is not invitation button. how can i add my new hotmail friends to chat on IM. the count of my friends who uses windows phon

  • creating user profiles, each with personal mysql data, using php 2012-03-07

    I'm trying to figure out the best practices for storing user data on a php/mysql site. let's say the website will host a service of saving people's input for items they have in their house. I have set up tables that includes: kitchen, bathroom, bedro

  • How can I add other text/characters to a MySQL query (://, 2011-04-05

    How can I add things to a MySQL query (://, <,=, etc.)? I'm trying to use the following code: <?php $con = mysql_connect("----------","---------","--------"); if (!$con) { die('Could not connect: ' . mysql_error()); } $add_something = "<a hr

  • How can I add a UIDatePicker Subview with working user interaction 2010-01-29

    I have a view based application which has some textboxes that I'm trying to populate with some pickers. For example, one of them will be for date selection. I'm using the following to add a new view to the bottom of my current view, then scroll the e

  • i can't add user accounts on my PC 2014-12-21

    i wanted to add another user account at my laptop.but everytime i clik the buttong nothing really happens.. --------------Solutions------------- Hi, Are you logged on as Admin? Try these to clear corruption in case it has a role. 1. Run DiskCleanup -

  • How can I add rows of data with dynamic images in Flex? 2011-01-19

    I want to add specific images to a datagrid row, depending on the data displayed on that row. These images need to be functional buttons with click handlers and everything. For example, if a row displays status of a certain element, like "Editable" t

  • Add User To Role in memeber ship Provider 2011-07-07

    I have gone through a video tutorial regarding Membership Provider in which he has done his coding in VB. The same code i used in C# but at this point i am getting an error as The best overloaded method match for 'System.Web.Security.Roles.Ad

  • Is it possible to change a user accounts role (with Cancan) automatically after a certain time? 2011-08-30

    In the app I'm making a user can own an account, and each account can be either free or premium (using roles and the Cancan gem). I want to be able to upgrade free accounts to a premium role and select a duration such as 2 months, then after the 2 mo

  • Can't add user or change password on Windows 7 Professional laptop 2012-05-20

    This came to light while trying to install SQL2012 Standard on my laptop. During the install, I received the message that the password I had selected for the sa user did not meet the length/complexity requirements. Looking at the local policies, I fo

Copyright (C), All Rights Reserved.

processed in 0.151 (s). 11 q(s)