Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programmatically creating a userProgrammatically creating a user
Previous
 
Next
New Post
5/27/2009 9:03 AM
 

I'm trying to create a basic class that will add a user when I pass in a username, password, and email address.  I keep obtaining the following error, though:

System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.UI.UserControl.get_Request() at DotNetNuke.Entities.Modules.UserModuleBase.get_UserId() in C:\dotnetnuke\Library\Components\Users\UserModuleBase.vb:line 470 at DotNetNuke.Entities.Modules.UserModuleBase.get_AddUser() in C:\dotnetnuke\Library\Components\Users\UserModuleBase.vb:line 275 at DotNetNuke.Entities.Modules.UserModuleBase.get_User() in C:\dotnetnuke\Library\Components\Users\UserModuleBase.vb:line 442

My code is as follows:

using System;
using System.Collections.Generic;
using System.Web;

//Added:
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Membership;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security;

namespace MakeCMS.SkinTokens
{
    partial class MAKEUser : UserUserControlBase
    {
        #region Private Variables

        private string FirstName;
        private string LastName;

        #endregion

        #region Properties

        private string First_Name
        {
            get
            {
                if (FirstName == null)
                    return "";
                else
                    return FirstName;
            }
            set
            {
                FirstName = value;
            }
        }

        private string Last_Name
        {
            get
            {
                if (LastName == null)
                    return "";
                else
                    return LastName;
            }
            set
            {
                LastName = value;
            }
        }

        new protected bool AddUser
        {
            get { return true; }
        }

        #endregion

        public bool CreateAcct(string UName, string HashedId, string EmailAddress)
        {
            try
            {
                if (UName!= null & HashedId!= null & EmailAddress != null)
                {
                    var UserInfo = User;

                    CreateFLName(UName); //Own class that just pulls the first and last name from the username.

                    string objResponse = "Error: Unknown Error";


                    UserInfo oUserInfo = new UserInfo();
                    oUserInfo.PortalID = PortalSettings.PortalId;
                    oUserInfo.Membership.Username = UName;
                    oUserInfo.Username = UName;
                    oUserInfo.FirstName = First_Name;
                    oUserInfo.LastName = Last_Name;
                    oUserInfo.DisplayName = UName;
                    oUserInfo.Membership.Email = EmailAddress;
                    oUserInfo.Email = EmailAddress;
                    oUserInfo.Membership.Approved = true;
                    oUserInfo.AffiliateID = Int32.MinValue;
                    oUserInfo.Membership.Password = HashedId;

                    UserCreateStatus objUserCreateStatus = DotNetNuke.Entities.Users.UserController.CreateUser(ref oUserInfo);

                    if (objUserCreateStatus == UserCreateStatus.Success)
                    {
                        throw new Exception("Success");
                        //objResponse = "Success";
                    }
                    else
                    {
                        throw new Exception("Failure:" + String.format("Error: {0}", objUserCreateStatus.ToString()));
                        //objResponse = String.format("Error: {0}", objUserCreateStatus.ToString());
                    }
                    return false;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                throw new Exception("Error creating account on "+DateTime.Now.ToShortTimeString()+": " + ex.ToString() + ".");
                return false;
            }
        }

 
New Post
5/27/2009 9:43 AM
 

Nevermind.  Figured it out.

I left " var UserInfo = User;" in my code which was throwing me off.  After removing it everything worked fine.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programmatically creating a userProgrammatically creating a user


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out