Copied to clipboard

Flag this post as spam?

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


  • Tommy Albinsson 121 posts 254 karma points
    Jun 09, 2011 @ 16:54
    Tommy Albinsson
    0

    Create new member from windows service

    Hello,

    I am creating a windows service that creates and updates members in umbraco. When using the standard asp.net membership api i thought it to be very simple. But i have not been able to get it right. Can someone please specify the configuration needed to get this to work?

    I have tested with the following configuration.

      <system.web>
        <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
            <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
          </providers>
        </membership>
      </system.web>

    which results in Could not load type 'umbraco.providers.members.UmbracoMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

    I have also tried to use the standard configuration from asp.net on the patterns site, but then it complains about a storedprocedure that does not exist.

    Thanks alot.

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 09, 2011 @ 20:17
    Richard Soeteman
    0

    Hi,

    Did you already checkout cmsimport. This can create and update the members for you. It's free up to the import of 500 members,The Pro version is a paid product but let's you schedule your imports for a given day and time,

    Cheers,

    Richard

  • Tommy Albinsson 121 posts 254 karma points
    Jun 10, 2011 @ 00:36
    Tommy Albinsson
    0

    Hi Richard,

    Thanks for the answer. I am looking for a more sync/update way of doing this. That is why i am doing it in a windows service. Members will be updated nightly and on a regular basis during the day. That is why i wan't to know what configuration to add and what assemblies to reference.

    Cheers.

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 10, 2011 @ 01:26
    Richard Soeteman
    0

    Hi Tommy,

    Easiest way to import as members is still use the Member API, in your webservice reference umbraco,cms and businesslogic dll's. Then you can use the Member object. It's marked as deprecated but I and many others use it all the time because setting properties using the asp.net membership API is much harder.

    Out of curiosity(since I wrote CMSImport). Apart from CMSImport PRO not being free, what's missing to support your requirement? It can handle scheduled updates, so every night you can import the Members.

    Hope the dll references helped you and hope to hear from you what's missing.

    Thanks,

    Richard

     

  • Tommy Albinsson 121 posts 254 karma points
    Jun 10, 2011 @ 08:37
    Tommy Albinsson
    0

    Hi Richard,

    Thanks again for you quick answer.

    Now that i think about it, maybe noting is missing but one of my problems is that say, ~ users is located in a Active Directory, and the rest is located in a ERP system. The ERP for holding the users is just a sql server withs om custom tables so there i see no problem with using cmsimport, but how about AD?

    The references helped me a bit on the way! Thanks, i still get null reference exception when trying to use Member.MakeNew (when getting the user from umbraco).I have the following in my configurationfile, is anything missing that you can think of?

    <connectionStrings>

        <add name="umbracoDbDSN" connectionString="server=umbracoServer;database=UmbracoMemberTest;user id=UmbracoMemberTestUser;password=qwerty" />

    </connectionStrings>

    And under System.Web i just copied it directly from umbraco's web config.

    <system.web>
        <!-- Membership Provider -->
        <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
          <providers>
            <clear />
            <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
            <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
          </providers>
        </membership>
        <!-- added by NH to support membership providers in access layer -->
        <roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
          <providers>
            <clear />
            <add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" />
          </providers>
        </roleManager>
      </system.web>

  • Tommy Albinsson 121 posts 254 karma points
    Jun 10, 2011 @ 08:42
    Tommy Albinsson
    0

    In my service, i am doing this.

    Member member = Member.MakeNew("testUser", MemberType.GetByAlias("User"), User.GetUser(0));

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 10, 2011 @ 08:53
    Richard Soeteman
    0

    Maybe it's the webservice not being authenticated, Think you might need a valid UmbracoContext which is available when login in. I would peek in the Umbraco source how they handle their webservice communication.

    Regarding your question about AD. You can write a simple DataAdapter to retrieve data from the AD. Checkout Section 8.4 of the documentation for and example.

    Cheers,

    Richard

  • Tommy Albinsson 121 posts 254 karma points
    Jun 10, 2011 @ 09:06
    Tommy Albinsson
    0

    I found out i missplaced the connectionstring, it should not be in the connectionstrings section, it should be in the appsettings section. My bad :)

    But still a couple of errors to resolve, i neede to reference a couple of more assemblies after putting the key in appsettings instead, but now i am back at null reference exception ;) I will check out how they do it in the webservices.

    Ok, since the ad adapter already is written it should not be a problem then. Maybe i should check cmsimport out first. On question though, i would like to create Groups for users if they do not exist. The scenario is like this, we get a user from ad or from erp which is connected to different "roles", when getting this user and creating it in umbraco a want the groups connected to the user automatically. I saw you video of importing via CSV, but then you have to applyt the groups manually and i want it done automatically.

    Cheers, thanks again.

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 10, 2011 @ 09:32
    Richard Soeteman
    0

    Hi Tommy,

    Yes check out the free edition which handles your situation well except for saving the definition and scheduling the import.I'm currently working on version 2.0 documentation and added this scenario to the samples section. Belowyou find a snippet of an event that assigns a membergroup based on a value in the datasource. It will even create the group when the group doesn't exists. It's sample code and didn't test it YET but it should be a good example for you to work with.

     

        /// <summary>
    /// Assign a membergroup dynamically based on a column in the Datasource Sample code
    ///
    /// </summary>
    public class AssignMemberGroups : ApplicationBase
    {
    /// <summary>
    /// Initializes the event handler in the constructor
    /// </summary>
    public AssignMemberGroups()
    {
    MemberImport.RecordImported += new MemberImport.RecordImportedEventHandler(MemberImport_RecordImported);
    }

    /// <summary>
    /// This event will be raised when a Member is Imported
    /// Use this event otherwise the groups will still be assigned by cmsimport
    /// </summary>
    void MemberImport_RecordImported(object sender, RecordImportedEventArgs e)
    {
    //No need to update when the record is skipped
    if (e.ImportAction != ImportActions.Skip)
    {
    //Cast the sender to a member
    Member member = sender as Member;

    //For this example the column holding group info is the GroupName columnn
    string groupName = e.Items["GroupName"].ToString();

    //Remove assigned groups first
    member.Groups.Clear();

    //Try to get the group
    MemberGroup memberGroup = MemberGroup.GetByName(groupName);

    //Membergroup is not found, create the group
    if (memberGroup == null)
    {
    memberGroup = MemberGroup.MakeNew(groupName, member.User);
    }

    //Assign the group to the member
    member.AddGroup(memberGroup.Id);
    }
    }
    }

     

    Thanks,

    Richard

  • Tommy Albinsson 121 posts 254 karma points
    Jun 10, 2011 @ 09:42
    Tommy Albinsson
    0

    Cool, i will check this out. I think i can find it very useful in more than one project!

    It seems like it is the Member.MakeNew method that does not work. It seems that my umbraco context is alright because the following work.

    User user = User.GetUser(0) <- returns admin user created when installing umbraco.

    MemberType mbt = MemberType.GetByAlias("User") <- gets the membertype i created for test.

    But when running

                    Member member = Member.MakeNew("testUser", mbt, user);
    i get the following exception.

       at umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(String loginName)
       at umbraco.cms.businesslogic.member.Member.MakeNew(String Name, String LoginName, String Email, MemberType mbt, User u)
       at umbraco.cms.businesslogic.member.Member.MakeNew(String Name, MemberType mbt, User u)
       .........

     

    Thanks again for your example above. Greatly appreciated!

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 10, 2011 @ 09:59
    Richard Soeteman
    0

    It might be that this context is only needed when you update data, that I don't know, sorry. Try the same in a usercontrol and your are sure ;)

  • Efe Oseya 5 posts 25 karma points
    Sep 16, 2012 @ 16:50
    Efe Oseya
    0

    Tommy,
    Did you ever resolve the issue with Member.MakeNew? I'm trying to implement a similar thing, but get a nullreferenceexception. The use and membertype exist.

    Thanks

    Efe 

    ----------------

    I've resolved my issue now

  • Ibrahim Uslu 3 posts 25 karma points
    Nov 19, 2013 @ 02:44
    Ibrahim Uslu
    0

    Try this...

     <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">

          <providers>

            <clear />

            <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider,umbraco.providers" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />

            <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider,umbraco.providers" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />

          </providers>

        </membership>

Please Sign in or register to post replies

Write your reply to:

Draft