Using Sitecore users in YetAnotherForum

YetAnotherForum (or YAF for short) is an open source discussion forum written in C# and .NET. Sitecore and YAF cannot run in the same IIS application (they can, if you change the YAF source code, which I will show in a later post), but with a little piece of open source code you are able to use the Sitecore users in YAF.

The open source code is available at:

The idea is to have Sitecore and YAF running in the same second-level domains: For example let your Sitecore website run at and YAF in
When users log into the Sitecore extranet, the user information is stored in a cookie which is then digested by YAF.

First you will need to download the code from and build it yourself.

Copy the YAFLogin.dll to your Sitecore /bin/ folder. Then copy the YAFLogin.dll and SitecoreLogin.dll to the YAF /bin/ folder. Also copy the /sitecorelogin/default.aspx page to YAF.

In order to save the extranet credentials, you must apply the following 2 lines of code to your Sitecore extranet login dialog:

// Create a SitecoreUser by logging into the Sitecore extranet
// and retrieve the user information
SitecoreUser user = SitecoreUser.Login(eUserName.Text, ePassword.Text, chkRememberMe.Checked);
// Store the SitecoreUser as a cookie. This cookie can be retrieved by YAF.

That’s it. The user information is persisted in a cookie which can be digested by YAF, as cookies can be shared across second-level domains. There are 2 methods of digesting the Sitecore extranet user. The first method is to call the /sitecorelogin/default.aspx page which will create the user in YAF (if not already existing) do a login a redirect to the default YAF page. The second method is to extend the default.aspx page of YAF with the following code:

protected void Page_Load(object sender, EventArgs e)
// Restore the sitecore user from the persistant storage (the cookie)
YAF.Sitecore.PersistenceManager manager = new YAF.Sitecore.PersistenceManager();
YAF.Sitecore.SitecoreUser user = manager.Restore();
if (user != null)
// Instantiate the login manager and log the Sitecore user into YAF
YAF.Sitecore.LoginManager loginManager = new YAF.Sitecore.LoginManager();
// The SitecoreUser is now logged in, and the cookie can be removed
// Load same page to let YAF read the session
catch (Exception ex)
Response.Write("Failed to login Sitecore Extranet user: " + ex.Message);

This code does the same as the /sitecorelogin/default.aspx but will be executed by every page in YAF you call.

You can read more about the source code at

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 6 and tagged , , , . Bookmark the permalink.

4 Responses to Using Sitecore users in YetAnotherForum

  1. Pingback: Running YetAnotherForum inside Sitecore « Brian Pedersen’s Sitecore and .NET Blog

  2. Robert Pate says:

    I’m not sure if this project is compatible with the 1.9.4 version of YAF. I used the DLLs from RC1 and got these build errors below. It’s alright though. I’d prefer to use full yaf integration anyway, so i’ll be giving that a try. Thanks for sharing all your work!

    Error 1
    The type or namespace name ‘ForumPages’ does not exist in the namespace ‘YAF.Classes.Utils’ \yaf\SitecoreLogin\Default.aspx.cs
    line 35
    col 84

    Error 2
    The type or namespace name ‘YafCombinedUserData’ could not be found
    line 71
    col 7 & 42

  3. Oleg Burov says:

    Hello, Brian.

    Sitecore Trac ( is no longer available. A new Sitecore Marketplace replace Trac. Is more powerful.

    YAF Single Sign-On shared source module has been moved to Sitecore Marketplace. The new URL is

    Could you please replace the old URL ( with a new one?

    Best Wishes, Oleg

  4. Ramit Suri says:

    Hi Brian. Great Blog. I’ve implemented single sign on. When I log in to sitecore extranet and redirect to forums, it shows me signed in. But logging out in forum and then signing in again with the same user name password created in sitecore user manager says that username password don’t match. As I’ve checked, the YAF users table doesn’t insert password for the user. And even inserting it manually doesn’t work. Can you tell me whats the problem here ?

    Thank you..:)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s