If you are reading this article, then you probably know about YAF (Yet Another Forum) and looking to use it.
For those who do not know, it is an open source forum (discussions) application written in asp.net and C#. It can be easily integrated with your current website to provide the Forum (Asking questions, getting answers) facility to your website users.
We also use the same forum application to power our community on this site here.
YAF can be used independently or can be integrated with your existing website. We are going to talk about the integration with another popular open source application for blogging called BlogEngine.net
Download YAF
The current version of YAF can be downloaded from here. I am using the v1.9.6.1 RTW BIN Zipped YAF. If you want to play with the YAF code or want to customize it, you should download the SRC code zip.
Download BlogEngine 2.6
The BE 2.6 can be downloaded from here. I am using the BlogEngine.NET 2.6 (web). If you want to play with the BE code or want to customize it, you should download the SRC code zip.
Integration of YAF 1.9.6.1 with BlogEngine 2.6
- Start with BE 2.6:
Extract BlogEngine.NET zip folder. We will start copying the YAF code in BE 2.6 code step by step.
- Set up Forum in a subfolder:
The best and clean approach of using Forum is to keep all the code related to Forum in a separate subfolder under your root website. For example, if your website code is placed at YOURWEBSITE.com (called root), then we should set up forum at YOURWEBSITE.com/Forum. The word Forum can be anything of your choice.
So, create a folder Forum in your website's root (BlogEngine.NET/Forum in our case).
- Unzip YAF and copy to existing website:
Unzip the YAF BIN code that you have downloaded. The file structure would look something like this:
YAF-v1.9.6.1-RTW-BIN\YetAnotherForum.NET[All Files and folders]
Copy all files and folders from above path to BlogEngine.NET/Forum folder. This brings all YAF code to your BE and need some folder movements to make it work.
- Move [App_*] folders to Root:
Move (Cut and paste) all [App_*] folders from BlogEngine.NET/Forum/ to BlogEngine.NET. App_Code and Bin folders are already available in BlogEngine.NET. So, just copy the contents.
YAF would have following folders that need to be moved: App_Browsers, App_Data.
- Move Bin folder to Root:
Move (Cut and paste) Bin folder from BlogEngine.NET/Forum to BlogEngine.NET.
- Create Database:
YAF needs a database to install itself. You can also use a SQL server express 2005 or 2008 to set up YAF. You may already have a database for BE installation (We are using the default XML storage for BE here to keep things simple). I would advise you to create a new one for YAF to keep things separate and clean. Right click 'App_Data' folder, select 'Add New Item'->'SQL Server Database' and to create a new SQL server DB.
- Merge web.config files of existing website and YAF:
This is the most important and time consuming part of integration. YAF has created separate config files for appsettings, mail,db and URL rewriting. If you also have the same set up, then make the following changes in respective files itself. We are going to make all entries in one single web.config only.
Download MERGED web.config
You can download this merged web.config file straightaway and skip all the merging steps given below.
YAF and BE Merged Web Config.zip (6.02 kb)
OR if you want to do the hard work, here are the detailed steps for you:
Open the existing website's web.config file from BlogEngine.Net folder and make the following changes step by step:
- Find following tag
< configuration > < configSections >
and add the following line (If it contains another tags, let them be there. Don't delete):
< configuration >
< configSections >
<section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" requirePermission="false"/>
</ configSections >
</ configuration >
- Find following tag
< connectionStrings >
and add the following line (If it contains another tags, let them be there. Don't delete):
< connectionStrings >
<add name="yafnet" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;" providerName="System.Data.SqlClient"/>
</ connectionStrings >
Keep the name of tag as 'yafnet'.
The connectionString in above tag should point to the database which you created in above steps. Change the name of DB (shown in red) with your DB instance name. I have kept the name as Database.
- Find following tag
< appSettings >
and add the following line (If it contains another tags, let them be there. Don't delete):
< appSettings >
<add key="YAF.ConfigPassword" value="SET A PASSWORD OF YOUR CHOICE"/>
<add key="YAF.BoardID" value="1"/>
<add key="YAF.EnableURLRewriting" value="true"/>
<add key="YAF.UseSMTPSSL" value="false" />
<add key="YAF.URLRewritingMode" value="Translit" />
<add key="YAF.UseSMTPSSL" value="false" />
<add key="YAF.DatabaseObjectQualifier" value="yaf_"/>
<add key="YAF.DatabaseOwner" value="dbo"/>
<add key="YAF.ConnectionStringName" value="yafnet" />
<add key="YAF.UrlRewritingPrefix" value="yaf_" />
<add key="YAF.ProviderExceptionXML" value="ProviderExceptions.xml"/>
<add key="YAF.BoardRoot" value="" />
<add key="YAF.FileRoot" value="~/Forum"/>
<add key="YAF.AppRoot" value="~/Forum/" />
<add key="YAF.ProviderKeyType" value="System.Guid"/>
<add key="YAF.MobileUserAgents" value="iphone,ipad,midp,windows ce,windows phone,android,blackberry,opera mini,mobile,palm,portable,webos,htc,armv,lg/u,elaine,nokia,playstation,symbian,sonyericsson,mmp,hd_mini"/>
<add key="YAF.ShowToolBar" value="true" />
<add key="YAF.AllowLoginAndLogoff" value="true" />
<add key="YAF.JQueryAlias" value="jQueryYAF" />
</ appSettings >
The passowrd that you specify here will be asked by YAF while setting up the databse schema.
The application root i.e. folder where Forum code resides should be ~/Forum
- Find following tag
< configuration >
and add the following line (If it contains another tags, let them be there. Don't delete):
< configuration >
<rewriter >
<rewrite url="^~/(.+?)? yaf_login?\.aspx(\?(.+))?$" to="~/$1Default.aspx?g=login&$5" processing="stop" />
<rewrite url="^~/(.+?)?yaf_info?\.aspx\?i=([0-9]+?)&url\=(.+)$" to="~/$1Default.aspx?g=info&i=$2&url=$3" processing="stop" />
<rewrite url="^~/(.+)?yaf_topics([0-9]+)p([0-9]+)(_([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/ $1Default.aspx?g=topics&f=$2&p=$3&$7" processing="stop" />
<rewrite url="^~/(.+)? yaf_topics([0-9]+)(_([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx?g=topics&f=$2&$6" processing="stop" />
<rewrite url="^~/(.+)?yaf_forum([0-9]+)(_([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx? g=forum&c=$2&$6" processing="stop" />
<rewrite url="^~/(.+)?yaf_postst([0-9]+)p([0-9]+)(_ ([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx?g=posts&t=$2&p=$3&$7" processing="stop" />
<rewrite url="^~/(.+)?yaf_postst([0-9]+)(_([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx? g=posts&t=$2&$6" processing="stop" />
<rewrite url="^~/(.+)?yaf_postsm([0-9]+)(_([-a-z0- 9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx?g=posts&m=$2&$6" processing="stop" />
<rewrite url="^~/(.+)?yaf_profile([0-9]+)(_([-a-z0-9]+))?\.aspx(\?(.+))?$" to="~/$1Default.aspx?g=profile&u=$2&$6" processing="stop" />
<rewrite url="^~/(.+)?yaf_([-0-9a-z_]+?)\.aspx\?(.+)?$" to="~/$1Default.aspx? g=$2&$3" processing="stop" />
<rewrite url="^~/(.+)?yaf_([-0-9a-z_]+?)\.aspx$" to="~/ $1Default.aspx?g=$2" processing="stop" />
</rewriter>
</ configuration >
NOTE: The above tags have been picked up straight from URLRewriter.config. You can also copy them from there for future releases.
- Find following tag
< httpHandlers>
and add the following line (If it contains another tags, let them be there. Don't delete):
< httpHandlers>
<add verb="GET" path="Resource.ashx" type="YAF.YafResourceHandler, YAF" />
</ httpHandlers>
- Find following tag
< httpModules >
and add the following line (If it contains another tags, let them be there. Don't delete):
< httpModules >
<add name="YafTaskModule" type="YAF.Core.YafTaskModule, YAF.Core" />
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter"/>
</ httpModules >
- Find following tag
< pages > < controls > :
and add the following line (If it contains another tags, let them be there. Don't delete):
< pages >
< controls >
< add tagPrefix="YAF" namespace="YAF.Controls" assembly="YAF.Controls"/>
<add tagPrefix="YAF" namespace="YAF.Controls.Statistics" assembly="YAF.Controls"/>
<add tagPrefix="YAF" namespace="YAF.Classes"/>
<add tagPrefix="YAF" namespace="YAF"/>
</ controls >
</ pages >
- Find following tag
< system.webServer > < modules > :
and add the following line (If it contains another tags, let them be there. Don't delete):
< system.webServer >
< modules >
<remove name="YafTaskModule"/>
<remove name="UrlRewriter"/>
<add name="YafTaskModule" type="YAF.Core.YafTaskModule, YAF.Core" preCondition="managedHandler"/>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" preCondition="managedHandler"/>
<remove name="session" />
<add name="session" type="System.Web.SessionState.SessionStateModule" />
</ modules >
</ system.webServer >
- Find following tag
< system.webServer > < handlers > :
and add the following line (If it contains another tags, let them be there. Don't delete):
< system.webServer >
< handlers >
< add name="YafHandler" preCondition="integratedMode" verb="GET" path="Resource.ashx" type="YAF.YafResourceHandler, YAF" />
</ handlers >
</ system.webServer >
- Existing Asp.net membership and YAF:
If you already have existing membership (user registration and login/log out functionality) enabled in your existing website, then you do not need any other settings now. You are done. But if you don't have any or want to switch to YAF's membership, you should add following tags for it:
- Find following tag
< system.web >
and add the following line (If it contains another tags, let them be there. Don't delete):
< system.web >
< authentication mode="Forms" >
< forms name=".YAFNET_Authentication" protection="All" timeout="43200" cookieless="UseCookies"/>
</ authentication >
</ system.web >
NOTE: This tag may already exist in your web.config. If it is already there, REPLACE it with the above one.
- Find following tag
< system.web >
and add the following line (If it contains another tags, let them be there. Don't delete):
< system.web >
< roleManager enabled="true" defaultProvider="YafRoleProvider">
<providers>
<clear/>
<add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafRoleProvider" type="YAF.Providers.Roles.YafRoleProvider"/>
</providers >
</roleManager >
<membership defaultProvider="YafMembershipProvider" hashAlgorithmType="SHA1" >
<providers >
<clear/ >
<add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafMembershipProvider" requiresUniqueEmail="true" useSalt="true" type="YAF.Providers.Membership.YafMembershipProvider"/ >
</providers >
</membership >
<profile enabled="true" defaultProvider="YafProfileProvider" inherits="YAF.Utils.YafUserProfile" >
<providers >
<clear/ >
<add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafProfileProvider" type="YAF.Providers.Profile.YafProfileProvider"/ >
</providers >
</profile >
</ system.web >
NOTE: These tags may already exist in your web.config. If they are already there, REPLACE them with the above ones.
Wow..we are done with merging the web.config files. The toughest battle has been won.
- Disable or Delete config file in Forum:
Since we have merged the YAF configuration with existing website, we should delete the config files given in BlogEngine.NET/Forum. These files shouldbe either excluded from project or deleted:
app.config, mail.config, db.config, urlrewriter.config and web.config
- Set up Forum as a control:
By default, YAF has its own ~/Forum/default.aspx and runs inside its own master page. If you are okay with this behavior, you can skip this step.
OR If you want, you can run the whole forum inside BlogEngine as a control. Open ~/Forum/default.aspx and replace the code with the following code:
< %@ Page Title="" Language="C#" AutoEventWireup="true" %>
<%@ Register TagPrefix="YAF" Assembly="YAF" Namespace="YAF" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" Runat="Server">
<YAF:Forum runat="server" ID="forum" BoardID="1">
</YAF:Forum>
</asp:Content>
- Run:
You should now run the YAF installation by launching the
~/Forum OR BlogEngine.NET/Forum
. This will open the ~/Forum/Default.aspx page and automaticaly divert you to ~/Forum/Install/Default.aspx if you are running it for the first time.
This will open up a wizard which will ask you for the configuration password (remember you entered it in web.config above - in our case it is, yaf). Enter the password and follow the wizard. Once the wizard completes, it will set up the database schema for running YAF.
That's it. Next time you open the ~/Forum OR BlogEngine.NET/Forum
link, you will see the YAF forum running.
Issues and Solutions

- Profile provider. It looks like YAF does not want you to use your own Profile provider. It allows you to use your own membership and role provider but throws error if you use a profile provider other than YAF.
So, as a fix to this issue, you should use the profile provider tags mentioned above for YAF. Membership and Role provider can be changed to your choice (Your own or YAF).
- If you get the following error:
Delegate registered to create instances of 'System.Web.HttpSessionStateBase' returned null.
Solution:
http://am22tech.com/s/22/Forum1/forum.aspx?g=posts&t=404
- Error: Could not find a part of the path '..BlogEngine.NET\Forum\~\Boards\Themes\'.
Solution:
The YAF.BoardRoot in appsettings should have the null string as its value.
<add key="YAF.BoardRoot" value="" />
- Error: Microsoft JScript runtime error: 'jQuery' is undefined
error on loading YAF Forum page?
Solution:
The Approot key in web.config should point to the following Forum directory
<add key="YAF.AppRoot" value="~/Forum" />
- BE 2.6 error:
Microsoft JScript runtime error: 'WebForm_InitCallback' is undefined.
Solution: Try to turn off "compress webresource.axd" in admin/settings/advanced, sometimes it causes this js error to pop up. Then refresh browser cache (ctrl + F5).
Source: http://blogengine.codeplex.com/discussions/366559/
- No style sheets applied in BE 2.6 admin area
Solution:
The solution that worked for me was to fetch the latest code base from the BlogEngine codeplex link. You can also do the same. You would need to first build the BE source code and then replace all the code (except the merged web.config) with the new one in our workspace.
Source: http://blogengine.codeplex.com/discussions/362817
-
Error :
Message=Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.
Solution
Make sure that the attributes enableSessionState and enableViewStateMac are set to true:
<pages enableSessionState="true" enableViewStateMac="true" enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
That is it. Good luck. If you face any issues, ask in comments and i will be glad to help you.