YAFLogo

hyperx
  • hyperx
  • 54.8% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
Hello all,

Can someone please give me a few pointers on doing this?

I've tried to integrate YAF code into ASP.NET website and I encountered a few issues discussed Here  and I could not go anywhere.

I decided to keep the applications separate, but use the same membership provider between my ASP.NET website and forum website. So, if I create a user in my music website, I want the user be able to use the same login credentials to login to YAF.

A few things of note.

- I can register successfully in both websites.

Now, how do I link the user I created in my ASP.NET website? I see this code in YAF. This calls YAF.Classes.Utils assembly, which I cannot reference in my application as this DLL is cumulatively brings up the problem mentioned Here .


// setup inital roles (if any) for this user
RoleMembershipHelper.SetupUserRoles( YafContext.Current.PageBoardID, newUsername );

// create the user in the YAF DB as well as sync roles...
int? userID = RoleMembershipHelper.CreateForumUser( user, YafContext.Current.PageBoardID );

// create profile
YafUserProfile userProfile = PageContext.GetProfile( newUsername );
// setup their inital profile information
userProfile.Location = Location.Text.Trim();
userProfile.Homepage = HomePage.Text.Trim();
userProfile.Save();

// save the time zone...
YAF.Classes.Data.DB.user_save( UserMembershipHelper.GetUserIDFromProviderUserKey( user.ProviderUserKey ), PageContext.PageBoardID, null, null, Convert.ToInt32( TimeZones.SelectedValue ), null, null, null, null, null );

Can someone who has already done this please give me a few pointers here?

Thanks,

HyperX.

Sponsor
jshepler
15 years ago

Hello all,

Can someone please give me a few pointers on doing this?

I've tried to integrate YAF code into ASP.NET website and I encountered a few issues discussed Here  and I could not go anywhere.

hyperx wrote:

I posted in that other thread (post #12) what I thought was wrong with your web.config. You never replied - did you try it?

I decided to keep the applications separate, but use the same membership provider between my ASP.NET website and forum website. So, if I create a user in my music website, I want the user be able to use the same login credentials to login to YAF.

hyperx wrote:

Make sure the applicationName attributes are the same in all the provider configs in both applications. Using the same provider isn't enough. Additionally, being seperate applications, they won't share authentication - meaning logging into one app won't log you into the other.

A few things of note.

- I can register successfully in both websites.

Now, how do I link the user I created in my ASP.NET website? I see this code in YAF. This calls YAF.Classes.Utils assembly, which I cannot reference in my application as this DLL is cumulatively brings up the problem mentioned Here .

hyperx wrote:

You don't have to do anything to link users. The first time an authenticated user visits the forum, yaf adds the user to its database. Because you said "I can register successfully in both websites", that makes me think that you don't have the providers in both applications configured with the same applicationName. Because you shouldn't have been able to register the second time with the same credentials.

I'm not at work and don't have the YAF source handy, but the YAF.Classes.Utils assembly has references to other YAF assemblies (which also have refernces to other YAF assemblies). You can't just drop that one assembly in your app, you have to put them all in. You should have gotten different compile errors than what you posted in that other thread.


not jsheLPer

mrtanvirali
15 years ago
hi,

i've done this using the following code:

try
                {
                    MembershipCreateStatus membershipStatus;

                    MembershipUser mu = Membership.CreateUser(UserName.Text, Password.Text, Email.Text,Question.Text,Answer.Text,true, out membershipStatus);
                    Roles.AddUserToRole(mu.UserName.ToString(), "registered");

                    // Display a status message           
                    ErrorMessage.Text += string.Format("User {0} was added to role {1}.",
                    mu.UserName.ToString(), "registered");
                }
                catch (MembershipCreateUserException ex)
                {
                    ErrorMessage.Text += GetErrorMessage(ex.StatusCode);
                }

the above code saves into the "yaf_prov_Membership" and when user login into the forum it automatically saves the user into the yaf_users table and sets roles for it

Schmakt
  • Schmakt
  • 55.4% (Neutral)
  • YAF Forumling
15 years ago
brilliant!

mrtanvirali, THANK YOU! 🙂