c# - Can't add user to role with SimpleMembership (MySQL) -
i'm trying use simplemembership mysql in code first project. initializer 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 "addusertorole":
an exception of type 'system.invalidoperationexception' occurred in mysql.web.dll not handled in user code
additional information: usertablename configuration not initialized.
the user added table "userprofile" (and "webpages_membership") , role "webpages_roles". "webpages_usersinroles" empty.
the providers in web.config (for simplemembership mysql):
<membership defaultprovider="mysqlsimplemembershipprovider"> <providers> <clear /> <add name="mysqlsimplemembershipprovider" type="mysql.web.security.mysqlsimplemembershipprovider,mysql.web,version=6.9.6.0,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=6.9.6.0, culture=neutral, publickeytoken=c5687fc88969c44d" connectionstringname="myconnectionstringname" applicationname="/" /> </providers> </rolemanager>
does know configuration isn't right here? it's strange because other things (creating users , roles) working fine without exceptions.
thanks in advance!
update
i have added attributes membershipprovider rolemanager.
<rolemanager defaultprovider="mysqlsimpleroleprovider"> <providers> <clear /> <add name="mysqlsimpleroleprovider" type="mysql.web.security.mysqlsimpleroleprovider, mysql.web, version=6.9.6.0, culture=neutral, publickeytoken=c5687fc88969c44d" connectionstringname="samandarservice_db" applicationname="samandarservice" usertablename="userprofile" useridcolumn="userid" usernamecolumn="name" /> </providers> </rolemanager>
another exception shows now:
cannot add or update child row: foreign key constraint fails (
ticket
.webpages_usersinroles
, constraintfk_roleid
foreign key (roleid
) referenceswebpages_roles
(roleid
))
the role correctly added roles table, mysql can't reference because of mysterious reason.
how fix issue?
Comments
Post a Comment