Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have resolved this with multiple profiles and providers, using the following hack:</p> <p>First: create a base class for your profiles. It doesn't have to contain all the fields; it's just important they share the same base class (I called this <code>CustomProfileBase</code>).</p> <p>Furthermore the following change in config:</p> <p><strong>app.config</strong></p> <pre><code>&lt;system.web&gt; &lt;membership defaultProvider="CustomSqlProviderA" userIsOnlineTimeWindow="15"&gt; &lt;providers&gt; &lt;clear/&gt; &lt;add name="CustomSqlProviderA" applicationName="websiteA" type="Authenticatie.A.CustomMembershipProvider, Authenticatie" description="A Membership" connectionStringName="profilesA" /&gt; &lt;add name="CustomSqlProviderB" applicationName="websiteB" type="Authenticatie.B.CustomMembershipProvider, Authenticatie" description="B Membership" connectionStringName="profilesB" /&gt; &lt;/providers&gt; &lt;/membership&gt; &lt;profile inherits="Authenticatie.CustomProfileBase, Authenticatie" defaultProvider="AProfielen" enabled="true"&gt; &lt;providers&gt; &lt;add name="AProfielen" applicationName="websiteA" type="Authenticatie.A.CustomProfileProvider, Authenticatie" connectionStringName="profielenA" description="A"/&gt; &lt;add name="BProfielen" applicationName="websiteB" type="Authenticatie.B.CustomProfileProvider, Authenticatie" connectionStringName="profielenB" description="B"/&gt; &lt;/providers&gt; &lt;/profile&gt; &lt;/system.web&gt; </code></pre> <p><strong>code</strong></p> <pre><code>// find the membershipprovider based on the property 'website' var membershipProvider = Membership.Providers.Cast&lt;MembershipProvider&gt;().Single(s =&gt; s.ApplicationName == (website == Website.A ? "websiteA" : "websiteB")); // find the according profileProvider var profileProvider = ProfileManager.Providers[website == Website.A ? "AProfielen" : "BProfielen"]; // here's the hacky part. There is a static field on the ProfileManager // that needs to be set. 'Membership' uses the ProfileManager to retrieve // and store the profile; so it's pretty much the only way FieldInfo cPr = typeof(ProfileManager).GetField("s_Provider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); cPr.SetValue(null, profileProvider); // Now we can retrieve the current user through our selected membershipProvider var user = membershipProvider.GetUser(gebruikersData.EmailAdres, false); if (user == null) { // create user: membershipProvider.CreateUser(mail, password, mail, null, null, true, null, out createStatus); // create according profile. ProfileBase uses Membership internal. var profile = (CustomProfileBase)ProfileBase.Create(mail); // set the default values, you can upcast your profile again profile.Save(); } </code></pre> <p>Now we have created a user in the according database along with a profile. You can retrieve the user through the <code>membershipProvider</code> and the profile through <code>ProfileManager.FindProfilesByUserName()</code>.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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