• hmillington
  • 50.6% (Neutral)
  • YAF Forumling Topic Starter
11 years ago
This topic has been discussed here before, and it looks as if many people are trying to do it without success (or without a working solution being posted here, at least), but do accept my apolgies if I've just been unable to find it.

I want to create user accounts programatically from another database of users. I've seen some snippets of code here that look like they might form the basis of doing it but nothing that provides a complete solution.

http://forum.yetanotherforum.net/yaf_postst9159_Add-User-Programatically.aspx .

However it doesn't compile as the lines containing a YAF reference claim 'reference to a non-shared member requires a object reference' and I know how I'd usually solve that problem in my own code, but I don't know enough about YAF or membership providers to do so here.

I'm proposing to run the code in the same appolciation at YAF, so the library code is available to it.

What do I need to add? And also, what does the "XXXX" refer to?



<%@ Page Language="VB" %>

Untitled Page


  • Tuff
  • 52.4% (Neutral)
  • YAF Forumling
11 years ago
I normally code in C# and you'll need to add the namespace:
using YAF.Providers;

I believe in VB, you need to do it as follows:
Imports YAF.Providers

As for the "XXXX", that is the AppName. Look in your yaf_prov_Application table and see what the ApplicationName is. The default is "YetAnotherForum".

Hope this helps.
  • Steve4
  • 81.2% (Honored)
  • YAF Lover
11 years ago
I'm trying to do the same thing and I can't get this code to compile. I copied the code above and converted it to C#. Some of the error message said that I needed a static reference to call some of the methods so I created objects like oRolesDB to call the static methods. Currently the error message is saying:

The type or namespace name 'DB' does not exist in the namespace 'YAF.Classes.Data'

Can anybody tell me what class or reference I need to complete this method? I'm also not sure why he's calling the foreach method because it looks like he's setting roles for the user that have already been set. Here's my broken code:

using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using YAF;
using YAF.Classes;
using YAF.Providers;
using YAF.Providers.Profile;

namespace YAF
public partial class LoadUsers : Page
protected void Page_Load(object sender, EventArgs e)

private void CreateUser(String sApplicationName, String sUserName, String sPassword, String sEmail)
YAF.Classes.Data.DB oDataDB = new YAF.Classes.Data.DB();
YAF.Providers.Roles.DB oRolesDB = new YAF.Providers.Roles.DB();
YAF.Providers.Profile.DB oProfileDB = new YAF.Providers.Profile.DB();
YAF.Providers.Membership.DB oMembershipDB = new YAF.Providers.Membership.DB();
String sPasswordHashed = FormsAuthentication.HashPasswordForStoringInConfigFile(sPassword, "md5");
Object oUserKey = oProfileDB.GetProviderUserKey(sApplicationName, sUserName);
oRolesDB.AddUserToRole(sApplicationName, sUserName, "Registered");
oMembershipDB.CreateUser(sApplicationName, sUserName, sPasswordHashed, "", 0, sEmail, "", "", true, oUserKey);
String[] sUserRoles = Roles.GetRolesForUser(sUserName);
foreach (String sUserRole in sUserRoles)
oDataDB.user_setrole(1, oUserKey, sUserRole);
Object oUserLogin = oDataDB.user_aspnet(1, sUserName, sEmail, oUserKey, true);
String sUserIDFormatted = String.Format("{0};{1};{2}", oUserLogin, 1, sUserName);
FormsAuthentication.SetAuthCookie(sUserIDFormatted, true);
  • Steve4
  • 81.2% (Honored)
  • YAF Lover
11 years ago
After doing a little more research it looks like the methods above are in the LegacyDB class. But when I try to reference that class I get the error: The type or namespace name 'LegacyDB' does not exist in the namespace 'YAF.Classes.Data'. But it does. Why doesn't this work?

YAF Logo Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved
About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button