Saturday, February 28, 2009

Intergrate Yet Another Forum 1.9.3RC2 with Umbraco 4

Since Umbraco doesn't have a integrated forum package yet I tried to integrate the latest version of YAF.

Here are the steps that I took and the issues that I encountered.

Preparing Umbraco

  1. Download and install Umbraco4 with Runway to keep it simple
  2. In Umbraco you create new documenttype called Forum and a matching template
  3. Add properties to this documenttype. I only added a title property for this tutorial.
  4. Add the forum documenttype to the allowed childnode types of the Runway homepage
  5. Change the Forum template so it uses the Runway master template
  6. Create a forum page and publish it.
  7. Go to the member section and create 2 Membergroups : Registered Users and Adminstrators
  8. Create a Membertype Registered user
  9. Create a user of the type Registered user and add it to the Admistrators group
  10. Modify the master template by adding code snippet 1 to the Runwaymaster template just before the ContentPlaceHolder
  11. Go to your website and login using the user you just created and confirm that it works

Preparing YAF

  1. Download and unzip YAF to a folder YAF under your Umbraco root
  2. Backup your Umbraco web.config
  3. Copy all the file is in the YAF bin folder to the Umbraco bin folder. If you got to your Umbraco backend UI now you see that it stops working. We solve that in the next step
  4. Open up the Umbraco web.config and add code snippet 2 to it at the bottom before the closing configuration tag. Now the Umbraco backend UI should work again. If not check the version of the AjaxToolkit.dll from the Umbraco zip file and the YAF zip file and change the version numbers in the code snippet
  5. Copy the App_Code folder from the YAF directory to the Umbraco App_Code folder
  6. UPDATE 23/03/2009 : Open up the file App_Code/YAF/Forum.cs and add this.Init += new EventHandler( Forum_Init );  to the constructor (public Forum()). Also add code snippet 9 to this file.
  7. Next open up the web.config and copy/paste code snippet 3 in to the appSettings section. These are the settings from the YAF app.config file with the needed modifications. If you run the forum page in a subdirectory like <yourwebsite>/blabla/forum.aspx you will have to change the baseUrl property to match this directory.
  8. Modify the appSetting umbracoReservedPaths to <add key="umbracoReservedPaths" value="/umbraco,/install/,/yaf/" />
  9. Add code snippet 4 to the Umbraco web.config in the configuration section. Modify the connectionstring so it connects to your YAF database. In this case I will use the Umbraco database.
  10. Add <add name="YafInitModule" type="YAF.Classes.Base.YafInitModule, YAF.Classes.Base"/> to HttpModules section of your Umbraco web.config
  11. Replace the pages section in the Umbraco web.config with code snippet 5
  12. Add code snippet 6 to the Umbraco web.config in the system.web section
  13. UPDATE 23/03/2009 : Add code snippet 8 to the file config/UrlRewriting.config
  14. Delete the bin and App_Code folder from the YAF directory

Install YAF

  1. Open up a browers and call <yourwebsite>/yaf/install/default.aspx
  2. In the first step enter the a password
  3. In step 2 install full text search if your database supports it
  4. In step 3 configure your forum with a existing user. Use the user we created during the setup of umbraco.
  5. In step 4 click finish. This will redirect to the homepage of your website

Using YAF in umbraco

  1. In Umbraco open up your forum masterpage and add <yaf:Forum id="yafForum" runat="server"/> between the asp:Content tags
  2. If you visit your forum page on the website you will see a ugly error. This is caused by a "bug????" in the Umbraco Membership Provider. To override this error create a file called YAFUmbracoMembership.cs in the App_Code folder of Umbraco. Copy code snippet 7 into this file.
  3. Change your Umbraco web.config so that the membership Provider uses Dawoe.Providers.YAFUmbracoMembership
  4. Change the Umbraco web.config so that profile is enabled.
  5. Open up the forum page again and voila !!! YAF integrated in Umbraco. Try to login and you will see that it works.
  6. Also try to create a new user in umbraco and Login in with that one.

Known issues

  1. Registering through the forum doesn't work. No workaround yet. Disable it for now in the YAF hostsettings.

If somebody finds other issues and/or solutions please report them and I'll update this post.

Code snippets

Code snippet 1 :

<asp:LoginView id="loginView" runat="server">
    <AnonymousTemplate>
        <asp:Login id="login" runat="server" />
    </AnonymousTemplate>
    <LoggedInTemplate>
        <asp:LoginStatus id="loginStatus" runat="server"/>
    </LoggedInTemplate>
</asp:LoginView>

Code snippet 2 :

 <!-- Ajaxtoolkit bindings -->
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="AjaxControlToolkit" publicKeyToken="28f01b0e84b6d53e"/>
            <publisherPolicy apply="no"/>
            <bindingRedirect oldVersion="1.0.10920.32880" newVersion="1.0.20229.26329"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31BF3856AD364E35"/>
            <publisherPolicy apply="no"/>
            <bindingRedirect oldVersion="3.5.0.0" newVersion="1.0.61025.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Code snippet 3 :

<add key="configPassword" value="" />
<add key="BoardID" value="1" />
<add key="EnableURLRewriting" value="false" />
<add key="databaseObjectQualifier" value="yaf_" />
<add key="databaseOwner" value="dbo" />
<add key="providerExceptionXML" value="ProviderExceptions.xml" />
<add key="UploadDir" value="~/yaf/upload/" />
<add key="ProviderKeyType" value="System.Int32" /> 
<add key="root" value="/yaf" />  
<add key="BaseUrl" value="~/yaf" />
<add key="BaseUrlOverrideDomain" value="false" />   

Code snippet 4 :

<connectionStrings>
    <add name="yafnet" connectionString="server=.\sqlexpress;database=umbraco;user id=umbracoUser;password=umbraco" />
</connectionStrings>

Code snippet 5 :

<pages validateRequest="false" smartNavigation="false">
    <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add tagPrefix="umbraco" namespace="umbraco.presentation.templateControls" assembly="umbraco" />
        <add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
        <add tagPrefix="YAF" namespace="YAF.Classes.UI" assembly="YAF.Classes.UI" />
        <add tagPrefix="YAF" namespace="YAF.Classes.Utils" assembly="YAF.Classes.Utils" />
        <add tagPrefix="YAF" namespace="YAF.Classes.Data" assembly="YAF.Classes.Data" />
        <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"/>
        <add tagPrefix="editor" namespace="YAF.Editor"/>
    </controls>
    <namespaces>
        <add namespace="YAF" />
        <add namespace="YAF.Classes.UI" />
        <add namespace="YAF.Classes.Utils" />
        <add namespace="YAF.Controls" />
        <add namespace="YAF.Classes.Data" />
    </namespaces>
</pages>

Code snippet 6 :

<profile enabled="false" defaultProvider="YafProfileProvider" inherits="YAF.Classes.Utils.YafUserProfile">
    <providers>
        <clear/>
        <add connectionStringName="yafnet" applicationName="YetAnotherForum" name="YafProfileProvider" type="YAF.Providers.Profile.YafProfileProvider"/>
    </providers>
</profile>

Code snippet 7 :

namespace Dawoe.Providers
{
    public class YAFUmbracoMembership : umbraco.providers.members.UmbracoMembershipProvider
    {
        public override string ApplicationName
        {
            get
            {
                return base.ApplicationName;
            }
            set
            {
                // Do nothing because umbraco doesn't allow empty applicationnames or applicationnames with a lenght greater than 0
            }
        }
    }
}

Code snippet 8 :

<add name="YafFramehelperRewrite" virtualUrl="framehelper.aspx(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/yaf/framehelper.aspx?$1" ignoreCase="true" />
<add name="YafAdvancedRewrite" virtualUrl="advanced.aspx(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/yaf/advanced.aspx?$1" ignoreCase="true" />
<add name="YafErrorRewrite" virtualUrl="error.aspx(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/yaf/error.aspx?$1" ignoreCase="true" />
<add name="YafResourceRewrite" virtualUrl="resource.ashx(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/yaf/resource.ashx?$1" ignoreCase="true" />
<add name="YafRewrite" virtualUrl="/yaf/forum.aspx(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/forum.aspx?$1" ignoreCase="true" />

Code snippet 9 :

private void Forum_Init(object sender, EventArgs e)
{
    try {
        ((umbraco.UmbracoDefault)this.Page).ValidateRequest = false;
        }
    catch {
        // catch error when page isn't called with umbraco master page
        }
}

35 comments:

Hartvig said...

Added an update to the Request Validation issue:
http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=21491

It's programmatically turned off in the umbraco core to support to turn it *on* programmatically (the other way around is *not* supported in .NET 2.0 - it is in 3.5). So in order for Canvas Editing to be possible, we had to do it that way.

Unfortunately, we didn't made it easy and obvious how to work around it.

In 4.0.1 I've added a control to make it easy.
Thanks for the heads up!

Jon said...

If you need to get uploading of files you need to change the upload path or create the folder Upload in the Umbraco root and also copy resource.ashx from you YAF folder to Umbraco root..

If ther is another way .. tell tell :)

Dave W said...

Hey Jon,

Thx for the report I will place this on my bugfix list.

neskire said...

Great article - works fine - and looks good ;)

To keep the member-type in the member-section in umbraco you can change the type of "UmbracoMembershipProvider" to "Dawoe.Providers.YAFUmbracoMembership" like:

"<" add name="UmbracoMembershipProvider" type="Dawoe.Providers.YAFUmbracoMembership" / ">"

Azrael said...

if you have different Boards, then create a property in the forum datatype and add this snippet to the template:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
umbraco.presentation.nodeFactory.Node n = umbraco.presentation.nodeFactory.Node.GetCurrent();
forum1.BoardID = int.Parse(n.GetProperty("boardId").Value);
}

</script>

<asp:Content ContentPlaceHolderID="CopiArteContent" runat="server">
<YAF:Forum runat="server" ID="forum1" ></YAF:Forum>
</asp:Content>

Almir said...

Quote: Added an update to the Request Validation issue:
http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=21491
End Quote

Great article, I solved most of the issues, however the one quoted above does not work for me.

I placed the suggested code snippet in the control codebehind, master page script to no avail.

Any suggestions will be much appreciated.

Also is there any way to get rid of register and login links in the YAF menu.

Dave W said...

@Almir : I updated the post with solution for this problem

Almir said...

@Dave - I solved the first problem by moving the code snippet to Page_Init handler.

I solved the second problem by removing the unwanted links from the YAF source code.

There seems to be another issue, if the user is removed from the Member section of Umbraco, it still stays listed in the list of YAF members, and that also may break the forum.

Tarek said...

How do you compare this work to install a forum under Umbraco, with that of DNN ? In terms of effort needed to get it up and running, and the provided features ?

I think DNN has a ready module for a Forum.

Is it possible to migrate the DNN Forum to Umbraco with YAF module ?

Zac said...

Great article.
FYI, There's a new version of YAF available. It's a full release version. Here:
http://sourceforge.net/project/showfiles.php?group_id=90539&package_id=95235&release_id=677843

vespaboy said...

Great article. All works fine until i downloaded the final release of 1.9.3 - now i get this error:

The file '/pages/forum.ascx' does not exist.

Which i assume is because it doesn't know the forum is in "/yaf" but no config settings have changed.

wamprat said...

Hi, I have been trying to follow the above instructions. (I am a noob to umbraco and YAF, and I am just putting this together for a POC).

When I try to go to the YAF install I get an about
Invalid language file C:\Inetpub\umbraco\languages\english.xml

Line 61: TimeZones.DataSource = YafStaticData.TimeZones( "english.xml" );

It would appear YAF is trying to look in the umbraco folder for this file when it should be looking in the YAF subfolder i.e. \umbraco\YAF\languages\.

I believe the file it is failing on is default.aspx.cs TimeZones.DataSource = YafStaticData.TimeZones( "english.xml" );

I could try and manually edit the cs file to look in the correct folder but no one else seems to of had these issues, so I am unsure this is the correct thing to do.
Thanks.

Anonymous said...

Works great but the "Member Type" Section doesn't appear when i use defaultProvider="YAFUmbracoMembership".
When i use: add name="UmbracoMembershipProvider" type="Dawoe.Providers.YAFUmbracoMembership" is the same.
What can i do?
Is there a solution for the register function of YAF?

Great article!

MenanaGus said...

I'm sure code snippet 6 is supposed to be <profile enabled=true

Ewoudt Kellerman
http://www.counton.com.au

Dave W said...

@Menanagus
If you look through the entire guide you will see that you need to enable at again later. I just disable it their so you can install YAF withou any trouble.

But I advise not use this anymore because there is a new version of YAF and this guide will not work anymore

Brendan said...

Hi Dave... Great work on this... followed instructions and all works fine... however I'm finding that only Umbraco Members that have been added to the Administrators group can add new threads or posts.

Any ideas? Help would be greatly appreciated.

davelane said...

Hey Dave, this is an extremely thorough tutorial! Thanks so much for posting.

I have a question - wondering if you or anyone else knows how I can setup an Umbraco user to have access to "Host Settings" in the YAF admin section?

Basically it seems I have to find a way to set a member as "isHostAdmin = true"

Any help would be greatly appreciated!

Cheers,
Dave

davelane said...

Hey all, I found a solution to my ishostAdmin issue: I simply went into pages/hostsettings.ascx.cs and commented out the following lines:

if ( !PageContext.IsHostAdmin ) YafBuildLink.AccessDenied();

Again, great post!
Dave

davelane said...

oh, and further to that solution, I then logged in to my forum as an admin user and navigated to the Administration section and modifed the URL to end with:

?g=admin_hostsettings

simps!

davelane said...

yes I'm replying a lot, but I thought it might be helpful to also add to the steps: move the contents of the YAF "images" folder to the umbraco "images" folder.

Dave W said...

Thanks everybody for the recent comments. I will be updating this post sometime soon to use the latest version of umbraco and YAF. Stay tuned

Richard said...

Thanks for the instructions. I have just installed with Umbraco 4.0.3. The issue I have is that in Umbraco, the Member Types folder is lost from the Member section, once I switch to your membership provider. So I can not see the Member Type details within Umbraco admin. Do you know how to resolve this?

agrath said...

Hi Dave

We're using YAF within umbraco 4.0.3 according to your guide.
Everything seems to be working except i'm noticing in fiddler 404s to the /ajaxpro handlers.
I've made sure that i've put the handler references into the system.web/httpHandlers and system.webserver/handlers sections but no dice. Still 404s.
I'm investigating this because i'm getting javascript errors and layout problems and a good place to start is to make sure that all resources are being loaded correctly.
Any help you can give would be great
Thanks,
Gareth
Sniper Systems Ltd
agrath at gee mail dot com

inDyHorse said...

Agrath:
I have a same problem, that you.
I debuged in few hours, but I found the solution... It's so simple:
You need to use same name, default provider and type in membersip node in the web.config:
For example:
<add name="YAFUmbracoMembership" type="Dawoe.Providers.YAFUmbracoMembership"........
And use this value in DefaultBackofficeProvider node in the config/umbracoSettings.config file.
After you set, it's will work :)

Vijay Velidi said...

Hi Dave,
I follow the instructions when i try to browse
http://localhost/yaf/install/default.aspx
i get below error pleasse help me to solve this

Server Error in '/YAF' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'YAF' could not be found (are you missing a using directive or an assembly reference?)

Vijay Velidi said...

Hi Dave when i try to browse the link below
http://localhost/yaf/install/default.aspx
i get following erro,Please guide me to solve this error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'YAF' could not be found (are you missing a using directive or an assembly reference?)

m said...

Has anyone tried to get this running with Umbraco 4.03? I can't get it to work.

Nikkho said...

Hi all,
How do you get around with the user registration thing? Do you just create a custom one?

Eric S said...

I got YAF 1.9.4 working with umbraco 4.0.3, and the registration is working as well.

1. Start with the instructions here
2. Replace the app settings in the web.config with the ones from the app.config file from YAF. Read the comments to know which ones to keep, modify, or leave out
3. Replace the pages element in the web.config with the one from the new YAF web.config, but make sure to leave the "umbraco" control element
4. To get the registration working, set the defaultMemberTypeAlias to "Registered User"

I think that was everything... a day of playing around with it, but I think it's working now.

Lordtoro said...

Thanks, it work for me with umbraco 4.0.4.1 ^^

Emil said...

When I go to http://localhost/Yaf/install/default.aspx I am redirected to http://localhost/Yaf/default.aspx?g=info&i=7 and get a server error saying that YafServices does not exist in current context.

Has anyone else had this happen? I'm trying to install YAF 1.9.4 RC2 with Umbraco 4.0.4.1.

Anonymous said...

Is there an update planned for YAF 1.9.4 and Umbraco 4.5 (.NET 4.0)?

Many thanks
Cornelia

Julien said...

Thanks for this tutorial and comments I've got it working with Umbraco 4.0.4.2/YAF 1.9.3. However I get the error "No member with username 'Guest' exists" when trying to display a topic containing "guest" posts. It looks like it's caused by the UmbracoRoleProvider. Did anybody's got a similar issue? Any help much appreciated.

Julien said...

Ok, I'm stripping down the forum interface so I found a dirty workaround by commenting the "userbox" information (/yaf/controls/DisplayPost.aspx - comment line 41). If that can help anyone.

Sobin said...

Hi is this work on latest umbraco or can you explain what changes i needed to do in order to make it working.