#1
Trying to integrate YAF with an existing web site. YAF is installed and working in a /Forum/ sub directory under the parent website.
Want users that are logged into the parent website to be automatically logged into YAF as well.

Was of the understanding that if created a SetAuthCookie in the parent site, the user would be automatically logged in on YAF as well.

Here's the code that creates the cookie:
System.Web.Security.FormsAuthentication.SetAuthCookie(Session("UserName"😉, False)

The Session cookie("UserName"😉 contains the username of the currently logged in user.

Web.config in the parent site has the following:
<authentication mode="Forms">
<forms name=".YAFNET_Authentication" protection="All" timeout="43200" cookieless="UseCookies"/>
</authentication>

There is no web.config in the /forum/ sub directory

I'm using the YAF membership, role, profile providers at this point, so they are the recommended sections in web.config

Anyone give me a clue where I need to go?

Reading through the forums here seemed to indicate it was as simple as setting the Authorization Cookie.
Do I have to create a custom membership provider as well?
Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
#2
Did the user actually exist in the yaf database? You need to make sure that the user actually exists

So first you check if the user exists and then login, or automatically register the user

if (this.Get<MembershipProvider>().ValidateUser(userName, password))
                {
                    FormsAuthentication.SetAuthCookie(userName, false);
                }
else
{
// register user first
}

UserPostedImage
  • tha_watcha
  • Rank: YAF.NET Project Lead
  • Reputation:
    Exalted
    100%
  • Medals:
    Medal of Honor: Portal Puzzle Master: Portal Puzzle Master for DNNMedal of Honor Key: Given to pillars of the community who are key players in the YAF community and project.DNN Master: DNN Module ManBug Killer Medal of Honor: Medal for being a kick-ass bug killer!Medal of Honor for the Support King: Support King! Amazing asset to the YAF.NET Community.
  • Joined: 06/03/2010
  • Posts: 4,017
  •  Germany
  • Thanks: 73 times
  • Was thanked: 1211 time(s) in 1036 post(s)
#3
In most cases, at least initially, the user wouldn't exist in the YAF database.

I can see that as part of the log in process for the main site, I could do the validate the user against the YAF membership provider and add him if he doesn't exist already.

The advantage of that obviously would be that I can then use the YAF membership, role, profile providers. The drawback would be that then I would essentially be keeping two user databases and trying to keep them synchronized.

Maybe to get things started using the YAF providers would be the best way to go. Then if things progress, then I can create my own providers to utilize the main site's databases.

Thanks for the tip. I'll play with adding the user to the YAF databases at main site log in if he doesn't already exist. If he does, then I can update the role and profile information in the YAF databases.
Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
#4
I've successfully called the YAF Membership Provider to create a new user if my logged in user from my main site doesn't exist in the YAF database. CreateUser MembershipCreateStatus returns "Success".

But the newly created user doesn't show up in the YAF Users admin functions.

My guess is that I probably have to use the YAF Role Provider and Profile Provider to add some additional information for the programmatically created user before he'll show up in YAF Users admin functions.

Can anyone provide the minimum other items I must add before a user will show up in the Users functions?
Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
#5
Interesting....

I just clicked on the "Sync All Membership Users" button on the Users page in the YAF admin function and my new user is there!

So, is there code I need to call when I programmatically create a new user to trigger whatever "Sync All Membership Users" does?
Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
#6
Made significant progress.

When the users log into my main site, I'm checking to see if they exist in the YAF databases by using the VerifyUser() in the YAFMembershipProvider. (Thanks tha_watcha!) If not, then I create them with CreateUser() in the YAFMembershipProvider. I then add the appropriate roles using AddUsersToRoles() in the YAFRoleProvider. Finally, I create the forms authentication cookie with:
System.Web.Security.FormsAuthentication.SetAuthCookie(username, false);

When the user clicks on a link to go to the forums, they show up there as logged in. Looks like I'm good to go from there.

I'm probably going to work on keeping the YAF databases synchronized with my master user database by updating email address, roles, and any other things that YAFProfileProvider might be tracking by updating the YAF database with the current information when the user logs into the main site. That way the latest user information will also be in YAF if the user jumps into the forums.

Not elegant, but in this case, I think it will be the most workable to get the forums launched.
If they start to get used regularly, then I can look at creating my own Membership, Roles, and Profile providers to work from my main database.
Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
#7
Originally Posted by: pwashburn@aol.com

Interesting....

I just clicked on the "Sync All Membership Users" button on the Users page in the YAF admin function and my new user is there!

So, is there code I need to call when I programmatically create a new user to trigger whatever "Sync All Membership Users" does?



Yes you can check the code all you have to do is call one method

RoleMembershipHelper.UpdateForumUser(user, pageBoardId)


user is the MembershipUser, and pageBoardId the forum board id

UserPostedImage
  • tha_watcha
  • Rank: YAF.NET Project Lead
  • Reputation:
    Exalted
    100%
  • Medals:
    Medal of Honor: Portal Puzzle Master: Portal Puzzle Master for DNNMedal of Honor Key: Given to pillars of the community who are key players in the YAF community and project.DNN Master: DNN Module ManBug Killer Medal of Honor: Medal for being a kick-ass bug killer!Medal of Honor for the Support King: Support King! Amazing asset to the YAF.NET Community.
  • Joined: 06/03/2010
  • Posts: 4,017
  •  Germany
  • Thanks: 73 times
  • Was thanked: 1211 time(s) in 1036 post(s)
#8
Migrated YAF integrated with my website to a new server, new SQL Server Express version, and a newer version of YAF.

Runs successfully as far as having a user logged into our parent website being automatically logged into YAF on the old server. The website configuration between the two is the same. YAF lives in the \forum under the parent website.

Old (and working) configuration is:
Win2003Server
SQL Express 2008
YAF version 2.0.0

New configuration is:
Win2012 server
SQL Express 2012
YAF version 2.2.1

Any clues what is different with the newer version of YAF?
SetAuthCookie is working.
The user already exists in the YAF database.
Same code that handles the transition from the parent website to YAF is in the newer configuration.
Pretty sure the web.config on the new server is set correctly, but.....
Everything else is as described earlier in this thread.


Any suggestions?

Topic Starter
  • pwashburn@aol.com
  • Rank: YAF Camper
  • Reputation:
    Friendly
    65%
  • Joined: 14/02/2015
  • Posts: 25
  •  United States
  • Thanks: 1 times
  • Was thanked: 1 time(s) in 1 post(s)
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

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

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved