Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ggesheva 15 posts 116 karma points
    Jun 12, 2020 @ 13:03
    ggesheva
    0

    Connecting CustomMembershipProvider to a separate DB

    Hi there! I replaced the default MembershipProvider with a custom one. During debugging I can see that the query that is executed from my custom MembersRepository class is returning result from the default DB(DB1) which keeps the content of my installation.

    Here is my Web.config

    ConnectionString:

    <connectionStrings>
    <remove name="umbracoDbDSN" />
    <add name="umbracoDbDSN" connectionString="server=random.database.windows.net;database=DB1;user id=ADMIN;password='*****'" providerName="System.Data.SqlClient" />
    <add name="membersDb" connectionString="server=random.database.windows.net;database=DB2;user id=ADMIN;password='*****'" providerName="System.Data.SqlClient" />
    

    And the membership:

     <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
      <providers>
        <clear />
        <add name="UmbracoMembershipProvider" type="ProjectS.Models.CustomMembershipProvider" connectionStringName="membersDb" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="false" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" allowManuallyChangingPassword="true"/>
        <add name="UsersMembershipProvider" type="Umbraco.Web.Security.Providers.UsersMembershipProvider" />
      </providers>
    </membership>
    

    How am I supposed to give to the UmbracoMembershipProvider in my web.config spare connection string so it can take from DB2?

  • Dhanesh Kumar MJ 165 posts 521 karma points MVP c-trib
    Jun 12, 2020 @ 13:17
    Dhanesh Kumar MJ
    0

    Hi ggesheva,

    Please have a look here https://github.com/Shazwazza/UmbracoIdentity/issues/82

  • ggesheva 15 posts 116 karma points
    Jun 18, 2020 @ 07:03
    ggesheva
    100

    After made checks: there was no property named connectionStringName in the class MembersMembershipProvider or it's base classes so I had to force it:

     public MembersRepository()
     {
            _db = new UmbracoDatabase("membersDb");
     }
    

    I am pretty sure it would be much better code if I extended my membership provider and added the connection string name through configuration.

Please Sign in or register to post replies

Write your reply to:

Draft