Copied to clipboard

Flag this post as spam?

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


  • mikachi 3 posts 23 karma points
    Nov 16, 2010 @ 00:00
    mikachi
    0

    Using membership provider to create members from code

    Hello, couldn't find the topic. I am using Membership.Create something like this

    MembershipCreateStatus mcs = new MembershipCreateStatus();
    var member = System.Web.Security.Membership.CreateUser(email, password, email, "kuku", "kisa", true, out mcs);

    I've tried shotter versions either.

    Can any one help me?

    P.S.

    Web config is follwoing

    <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>

    And i recieve this exception

    System.NullReferenceException: Object reference not set to an instance of an object.
    at umbraco.cms.businesslogic.Content.CreateContent(ContentType ct)
    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, String Email, MemberType mbt, User u)
    at umbraco.providers.members.UmbracoMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status)
    at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status)
    at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, MembershipCreateStatus& status)
    at WebServiceProxy.RegisterMember(String email) in d:\Development\C#\P&K\code\LF-GRP\trunk\LG.WebSite\App_Code\WebServiceProxy.cs:line 48
  • Richard Soeteman 4035 posts 12842 karma points MVP
    Nov 16, 2010 @ 08:45
    Richard Soeteman
    1

    Hi,

    You need to create a Member Type in Umbraco and copy that alias to your web.config file as DefaultMemberTypeAlias (replaces "Another Type")

    Cheers,

    Richard

     

  • mikachi 3 posts 23 karma points
    Nov 16, 2010 @ 08:57
    mikachi
    0

    Thanks for your fast reply,

    I did what you've told and error changed to the SQL server one. It can not find server. Should I add some configuration to tell provider the right connection string?

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Nov 16, 2010 @ 09:01
    Richard Soeteman
    0

    What's the error? You shouldn't set the connectionstring for membership its the same as your Umbraco Connectionstring

  • mikachi 3 posts 23 karma points
    Nov 16, 2010 @ 09:06
    mikachi
    0

    This one:
    umbraco.DataLayer.SqlHelperException: Umbraco Exception (DataLayer): SQL helper exception in ExecuteScalar ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteScalar(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) at umbraco.DataLayer.SqlHelpers.SqlServer.SqlServerHelper.ExecuteScalar(String commandText, SqlParameter[] parameters) at umbraco.DataLayer.SqlHelper`1.ExecuteScalar[T](String commandText, IParameter[] parameters) --- End of inner exception stack trace --- at umbraco.DataLayer.SqlHelper`1.ExecuteScalar[T](String commandText, IParameter[] parameters) at umbraco.cms.businesslogic.member.Member.IsMember(String loginName) at umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(String loginName) at umbraco.providers.members.UmbracoMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, MembershipCreateStatus& status) at System.Web.Security.Membership.CreateUser(String username, String password, String email) at WebServiceProxy.RegisterMember(String email) in d:\Development\C#\P&K\code\LF-GRP\trunk\LG.WebSite\App_Code\WebServiceProxy.cs:line 48

  • Eduardo 106 posts 130 karma points
    Nov 17, 2010 @ 12:32
    Eduardo
    0

    Hi mikachi,

    Is the first time you deal with a SQL Server DataBase?

    The problem is due to your database configuration.

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    Take a look into SQL Server configuration manager->Protocols for . Within this section, ensure "named pipes" status is "enabled"

    Also, consider checking the status of all the SQL Server services (SQL Server, SQL Server Browser..). These all must be enabled.

    HTH.

    Sincere regards,
    Eduardo Macho

  • Lincoln Vu 8 posts 29 karma points
    Jun 06, 2012 @ 19:36
    Lincoln Vu
    0

    Richard Soeteman's solution works for me. I got registration working before messing with Umbraco member types in its control panel. I just change 'Another Type' in web.config to the type I have in the control panel as instructed. Thanks.

  • Ranjit J. Vaity 66 posts 109 karma points
    Sep 14, 2012 @ 14:39
    Ranjit J. Vaity
    0

    Thank you, Richard, you are awsome. :)

     

  • fabio 87 posts 107 karma points
    Sep 16, 2012 @ 11:58
    fabio
    0

    Hello and thanks in advice

    how does it work when i have more then one Member type defined?

     

    Fabio

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Sep 17, 2012 @ 05:51
    Richard Soeteman
    1

    Hi Fabio,

    This is only possible with one media type. If you have more than one Media type, Use Member.MakeNew, based on the internal Member API of Umbraco.

    Cheers,

    Richard

  • fabio 87 posts 107 karma points
    Sep 17, 2012 @ 22:22
    fabio
    0

    Thanks richard

     

  • CelticHarp 12 posts 52 karma points
    Apr 02, 2013 @ 09:20
    CelticHarp
    0

    Hello, I'm using Umbraco 6 and I have 2 member types. Do I still have to stick with the deprecated Member.MakeNew in order to be able to use both types at my code?

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Apr 02, 2013 @ 09:31
    Richard Soeteman
    0

    Yes,

    still the best way to support both types and way more flexible than Membership API.

    Cheers,

    Richard

  • CelticHarp 12 posts 52 karma points
    Apr 02, 2013 @ 10:21
    CelticHarp
    0

    Thank you :)

Please Sign in or register to post replies

Write your reply to:

Draft