YAF Integration to Umbraco 4

For a website we are currently working on, we needed a Forum.  The new Forum4Umbraco is still in early development so we turned to Yet Another Forum.  This post describes how to integrate YAF into Umbraco 4 as a User Control.

This means you can create a template in Umbraco, and then insert the following line(s) of code to get an instant forum:

<form runat="server">
    <yaf:Forum runat="server" ID="forum" />

This was also possible because we do not need to share Membership information between Umbraco and YAF.  It may well be possible to share membership, and it’s something I’d like to look into if I ever get the time!

YAF Install Steps

1. Install Umbraco as usual, for instance into C:\Inetpub\wwwroot

2. If required, create a new database for YAF.  Alternatively, YAF can share the same database as Umbraco.

3. Create a directory for YAF, e.g. wwwroot/yaf

4. Unzip YAF files into wwwroot/yaf

5. Temporarily rename umbraco web.config to _web.config

6. Rename wwwroot/yaf/default.config to wwwroot/yaf/web.config

7. Enter a DB connection string into yafnet.config, into the <connstr/> tag. If sharing the database with the Umbraco install, copy the DB connection string from the “umbracoDbDSN” element in web.config into yafnet.config.  Note the “datalayer” keyword is not supported.

For example, if the Umbraco web.config contains the entry:

<add key="umbracoDbDSN" value="datalayer=SqlServer;Server=.\sql2005;Database=umbraco;
    User ID=umbraco_user;Password=password;Trusted_Connection=False" />

Then copy the connection string but do not include the datalayer section, e.g. yaf.config should contain:

<connstr>Server=.\sql2005;Database=umbraco;User ID=umbraco_user;Password=password;

7. Still editing yaf.config, add a <root>/yaf</root> element.

8. In IIS create a new virtual application on the wwwroot/yaf directory:

  • Right-click on the /yaf directory in IIS
  • Choose “Properties” from the context menu
  • Click the “Create” button on the Properties dialog
  • Click OK

NOTE: at this point on the Umbraco website will stop functioning.  It will begin working again once the YAF application is removed (later in this guide).

9. Open a web browser, and navigate to http://www.mywebsite.com/yaf/install.  Follow the YAF installation wizard instructions.

10. Navigate to http://www.mywebsite.com/yaf and check that the forum is working.

Get Umbraco Working again

11. Right click on YAF, choose properties, click the “Remove” button to disable the YAF application.

Note: The Umbraco web application will now begin working again.

12. Move the yaf.config file to the root website directory e.g. wwwroot/

13. Rename wwwroot/_web.config back to web.config

14. Rename wwwroot/yaf/web.config back to wwwroot/yaf/default.config

15. Update web.config with config settings from the /yaf/default.config

 <section name="yafnet" type="yaf.SectionHandler,yaf"/>

 <yafnet configSource="yafnet.config"/>

 <authentication mode="Forms">
    <forms name=".YAFNET_Authentication" timeout="525600" />

 <customErrors defaultRedirect="error.aspx" mode="RemoteOnly"/>

Note that you will need to comment out the following line in the web.config file:

<forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" />

16. Copy or move wwwroot/yaf/yaf.dll to wwwroot/bin/yaf.dll

17. Copy or move wwwroot/yaf/framehelper.aspx to wwwroot/framehelper.aspx

Add the forum to your website.

Create a document type and a template.  The template will look something like this:

<%@ Register TagPrefix="yaf" Namespace="yaf" Assembly="yaf" %>
<%@ Register TagPrefix="yc" Namespace="yaf.controls" Assembly="yaf" %>
<asp:Content id="Forumcontent" ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <form runat="server">
        <yaf:Forum runat="server" ID="forum" />

A Problem

Unfortunately there is a problem.  The YAF User Control will not work properly – it will attempt to reference default.aspx which is ‘owned’ by Umbraco.  This can be fixed using UrlRewriting.

A solution

To get around this:

1) Obtain the nodeId of the forum.  One way to do this is to log into the Umbraco Backend, place your mouse pointer over the forum node, and look at the browser status bar.  This will contain the node id.
For the purpose of this tutorial, we will assume the Node Id is 9999.

1) Update urlRewriting.config with the following (Note the Node Id in bold should be replaced with your node id):

        <!-- Redirect any requests for the-forum.aspx to forum.aspx -->
        <add name="forum-redirect"
                    redirectMode="Permanent" />
        <!-- Internally rewrite the url -->
        <add name="forum-rewrite"
                    ignoreCase="true" />

2) Ensure that the page (node) in Umbraco which contains the forum is called “Forum” and resolves to the url, “/forum.aspx”.

Note: Alternatively you could add a property to the Document Type called “umbracoUrlName” and set the value of that property to “the-forum”.

3) Ensure that there is NOT a page in Umbraco which resolves to “forum.aspx” (perhaps add to the list of reserved names?)

4) Ideally, any links (in templates, xslt etc) to the forum should link to “/forum.aspx” – NOT “the-forum.aspx”.  This means when linking to the forum, avoid using umbraco.library:NiceUrl(…)

Note: This is a recommendation rather than a necessity.  The “forum-redirect” rule above will ensure that all links to the forum will work.

Thats it – we’re done.  The forum should now be visible at www.mywebsite.com/forum.aspx , embedded into an Umbraco page.

Reserved Paths

You will also need to add /framehelper.aspx to the list of reserved paths in web.config

<add key=”umbracoReservedPaths” value=”/umbraco,/install/,/bingo,/framehelper.aspx” />

Also, if you wish to place the forum in a directory other than the root of your website, you will need to add a url rewriting rule for framehelper.aspx.

E.g. if you place the forum in /subdir/forum.aspx, you will need the following rule in urlRewriting.config:

<add name=”forum-reply-rewrite”
ignoreCase=”true” />


In fairness I should mention that most of the implementation details on how to embed YAF are actually covered on the YAF website.  Also, once I had worked out how to integrate YAF into Umbraco, I stumbled across this post by Skiltz on .NET, Integrating YetAnotherForum.net into Umbraco.  This post is concerned with Umbraco v3 but the steps are much the same so it’s great to see that others have been able to get this to work.  In this case, YAF was recompiled to get around the default.aspx issue – I solved this problem using UrlRewriting.  If you’d rather not use the UrlRewriting, you could try using the yaf.dll file provided by Skiltz instead.

Also thanks to Lars (see comments, below) for his tip on the use of the NodeId in the URL Re-write.

  • I'm not sure what version you're running, but have you updated to the latest; 1.9.3? I'd love to hear if you hit any obstacles to avoid in the process.

  • Adz

    I'm afraid I haven't upgraded the forum to the latest version! Do let me know if you discover any obstacles with 1.9.3

  • Jason M

    Hi the first obstacle I noticed was the instructions do not match. In version 1.9.3. there files are different. Would you be able to help with this new config?

  • Adz

    I'm afraid that YAF has moved on, but I have not yet had time to update. There is a really good tutorial elsewhere, however - http://dawoe.blogspot.com/2009...

  • Hi,

    <quote>1) Obtain the nodeId of the forum. One way to do this is to log into the Umbraco Backend, place your mouse pointer over the forum node, and look at the browser status bar. This will contain the node id.
    For the purpose of this tutorial, we will assume the Node Id is 9999.</quote>

    Wich node do you mean, of the page, document or template? I got an

    No umbraco document matches the url 'http://www.netsyne.com/1150.as...
    umbraco tried this to match it using this xpath query'1150')

    For all the three options.

  • Adz

    Just had a look at your site and it seems to be configured differently to the sites I have encountered. Specifically, it does not allow you to use urls like, "1050.aspx".

    It might be worth asking at the Umbraco forum if there is a web.config setting which needs to be enabled.

    Alternatively, avoid using the numeric aspx file and use the 'old' method, in struck-out text above.

  • Adz

    Hi Roel,

    The node ID I am refering to is of the Page. You can obtain this in the Content Section of the Umbraco backend provided you have a status bar in your browser. The bottom left of the browser will say something like,

    If you take the number in the brackets, you should be able to locate the page as follows,


    If your browser shows a web page then you have found the correct node id.

    Have you tried using the deleted method in the post (the information which has strike-through) rather than the node id method?

  • Hi Adz,

    Thanks for replying! I got it figured out!!


  • Shufflemoomin

    I simply cannot get the forum to point to anywhere other than the root default.aspx which takes me back to my umbraco homepage. The suggestions above don't seem to work for me.

  • Kevin

    Hey having problems with the web config and updating it with the lines from the config file. should the lines being inserted grouped together or moved into relevant sections through out the config file.

    also point 16. should it read Copy or move wwwroot/yaf/bin/yaf.dll to wwwroot/bin/yaf.dll if so you have ommited the bin folder?

    however not got any further then 17 cos my webconfig fails to work can you clarify that section?

  • Adz

    Hi Kevin

    Regarding the config file, you'll need to place/update the lines in the relevant section of the web.config file.

    For example look for a tag which reads, <section ...=""/>
    Then add <section name="yafnet" type="yaf.SectionHandler,yaf"/> just below it.

    You should already have a section <authentication mode="Forms">.
    So edit the line which begins <forms name="..." to="" read:="" <forms="" name=".YAFNET_Authentication" timeout="525600"/>

    You should also have a line which begins <customerrors ...="" so="" replace="" that="" line="" with,="" <customerrors="" defaultredirect="error.aspx" mode="RemoteOnly"/>

    Point 16, I'm pretty sure yaf.dll should be copied from wwwroot/yaf/yaf.dll - however, if it is not present there, and is present in wwwroot/yaf/bin/yaf.dll then use that file instead!

    It may also help to take a look at http://wiki.yetanotherforum.ne...

  • Kevin

    Sussed it although being a relative newbie to umbraco now stuck on doc type and template created them both but its not working when u load the page up on the front end.

    would be grateful if you could get in touch im sure i need to do something more to the doctype as well as the template.

  • Adz

    Hi Kevin

    I'd be happy to help if I can. I'll need more information tho! How about posting on the Umbraco forum, http://forum.umbraco.org - either myself or one of the other guys would be able to take a look at what you've done?

    All the best


  • Thanks for the post. We are looking at yaf and umbraco in a client project.

    An easy way to get around the rewriting problem is just to use the node id´s in the rewriting rules.

    Kind regards
    Lars Buur

  • Adz

    I've updated the post with your tip regarding Node Id.
    Thanks again! - Adz

  • Adz

    Hi Lars, thanks for the tip! I'll try it out and update the post.


blog comments powered by Disqus