Something is really confusing how roles and membership tables establish relationships
I know how to create users and assign them to roles etc., but when I tried to dig deeper into how roles and membership tables can establish relationships among themselves, I completely lost (BTW - I am making to know how external / primary keys;))
BTW - I created tables in databases using the aspnet_sqlreg wizard
Q1 - Both SqlRolesProvider and SqlMemebershipProvider have an ApplicationName property. I thought that in order for both providers to be able to create a relationship between their users and roles, they both had to use the same value for the ApplicationName property. But it doesn't seem to be the case.
A) Anyway, I am assuming that the SqlRolesProvider.ApplicationName property is only used to distinguish between entries in the table belonging to different role providers, but they don't use this property to bind their roles only to membership providers with the same ApplicationName value?
B) But wouldn't it be most practical if role providers could only be bound to membership providers with the same ApplicationName value (thus where SqlRolesProvider.ApplicationName == SqlMemebershipProvider.ApplicationName
) ?!
Q2 - I was also interested in whether roles and users could be related if the role provider was connected to DB1 and the membership provider was connected to DB2. Somehow I was still able to assign users to different roles, even though the roles were defined in a different database.
A) But why? Namely, if SqlRolesProvider.ApplicationName = "roleP" (ApplicationID = 10) and SqlMembershipProvider.ApplicationName = "membership" (ApplicationID = 100), then for a table in DB1 to be related to a table in DB2, they would have to refer to on top of each other via an ApplicationName record (actually via ApplicationID), which will act as a foreign / primary key.
But the point is, none of the foreign key fields in the DB1s tables have a value equal to SqlMembershipProvider.ApplicationID = 100, which suggests that there is no relationship between the tables in DB1 and DB2 (I know this is not a case, so how Im capable of assigning users to roles). So what am I missing?
thanks
EDIT:
Don't know if anyone else would read this, but I did some more digging and got even more confused:
If both roles (with application name = R1 and applicationID = 10) and the membership provider (with application name = M1 and with ApplicationID = 100) are in the same database, then creating a new user causes table 2 aspnet_Users to create two records for one user name-one with ApplicationID = 10 and others with ApplicationID = 100. As far as I know, when creating a new user, only one field should be added to aspnet_Users (with ApplicationID = 100). Eh ?!
a source to share
You looked at the aspnet_UsersInRoles table. This is the table that links the user to the role. RoleProvider is meant to be separate from MembershipProvider so that you can have them in separate databases. Additionally, it allows you to configure roles for one application name and reuse those roles in two separate applications, each with a different application name for the membership provider. Don't get hung up on the mentality that you must have the same app name for both vendors, or that your app name must match the running app. You don't need to have any name if you don't want to. Hope it helps.
a source to share