13 years ago
I thought I'd post how I got YAF to work with my .net App. It doesn't use any of the built in login stuff and so by following some of the instructions and making things up I got it to work. I tried to follow the wiki but it seems to be missing things or is out of date.

I have separate DBs (YAF and mine) but the website is merged (i.e. it's not a different virtual server or domain).

I basically took the YAF web.config and put my things into it rather than the other way round. As my app is a Web Application Project rather than a website project I had to compile all the DLLs for the classes and then put the things in the App_code folder into website root. The main thing to remember here is that some of the classes will compile at runtime and others not. Basically you right click on e.g. Forum.cs and click properties. Then change the build action to content. All the files in Modules I have as content too.

When I login to my website I put the following code in:

                YafMembershipProvider mb = (YafMembershipProvider)System.Web.Security.Membership.Providers["YafMembershipProvider"];    
                int? forumUserID = 0;

                if (!mb.ValidateUser(username, password))
                    MembershipCreateStatus status;
                    MembershipUser forumUser = mb.CreateUser(username, password, user.Email, "question", "answer", true, null, out status);

                    // create the user in the YAF DB as well as sync roles...
                    forumUserID = RoleMembershipHelper.CreateForumUser(forumUser, 1);

                    RoleMembershipHelper.SetupUserRoles(1, username);
                    RoleMembershipHelper.AddUserToRole(username, "Registered");

                    // create empty profile just so they have one
                    YafUserProfile userProfile = YafUserProfile.GetProfile(username);
                    userProfile.Homepage = ConfigurationSettings.AppSettings["siteurl"] + "User/Profile.aspx?ID=" + user.ID;

                    // setup their inital profile information
                    DataTable results = YAF.Classes.Data.DB.user_find(1, false, username, user.Email);
                    if (results.Rows.Count>0)
                        forumUserID = (int)results.Rows[0]["UserID"];

                if (forumUserID.HasValue)
                    string thumbnailUrl = "/images/nophoto.gif";
                    where = new PredicateExpression();
                    where.Add(PhotoFields.User == user.ID);
                    where.AddWithAnd(PhotoFields.IsVideo == false);
                    where.AddWithAnd(PhotoFields.Main == true);
                    where.AddWithAnd(PhotoFields.Private == false);
                    PhotoCollection photos = new PhotoCollection();
                    if (photos.Count > 0)
                        thumbnailUrl = photos[0].ThumbFilename;

                    YAF.Classes.Data.DB.user_saveavatar(forumUserID, ConfigurationSettings.AppSettings["siteurl"] + thumbnailUrl, null, null);
                FormsAuthentication.SetAuthCookie(username, false);

There are some extra things in there for adding the avatar and the homepage in here.

If you have the websites as separate entities then you'll need to do the machine token thing that you'll have seen but I didn't need that.


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