BlogEngine 2.6: Non-primary blog issues

by pinkbegemot 3. April 2013 14:03

 

When you create a new blog as a non-primary one some features of the  BlogEngine 2.6 won’t work, though you can’t discover it right away. But the good news is that it can be tweaked!  So far I have discovered the following issues for a non-primary blog:

  • Widget zone doesn’t work
  •  File upload fails
  •  Globalization stumbles

 Widget zone doesn't work on update

SyMPTOMS

You want to add widgets to a WidgetZone in a non-primary blog. The widgets get added, but when you hit  F5 to refresh the page the widgets are not rendered.

The trouble is with the “BlogEngine.Core.Blog. CurrentInnstance” variable – it is supposed to return the current instance, but it doesn’t always do so (contrary to our expectations).
If you debug the application (setting break points at numerous calls to “BlogEngine.Core.Blog. CurrentInnstance” inside the “WidgetZone” framework classes and in the “Global.asax.cs” ) you will discover that you get the correct instance returned on the first two calls. But as the execution continues, the return value changes and starts pointing to the primary blog. This happens during requests for scripts files, styles, etc. which is accurate, in fact. But this value also gets passed to your WidgetZone  cache, which results in actual adding the widgets to the primary blog’s WidgetZone, but rendering  the cached version of your non-primary blog’s WidgetZone.

RESOLUTION

1.       The workaround I had to put up with is to make some changes in the code to force  BlogEngine always return the primary blog instance as far as the WidgetZone’s rendering is concerned.

  1.  Add a new method to the “BlogEngine.Core.Blog.cs”. It will return your primary blog.

       public static Blog PrimaryBlog{
               
    get { return _primary jQuery152020093221597779243_1364990635002 (_primary = blogs.FirstOrDefault(b => b.IsPrimary))};  
         

  2. Search for  all “Blog.CurrentInstance” calls in all the classes in the WidgetZone framework .

    In the BlogEngine .NET files:

    admin\WidgetEditor.aspx.cs

    App_Code\Controls\WidgetBase.cs
    App_Code \Controls\WidgetEditBase.cs
    App_Code \Controls\WidgetZone.cs

  3. Find and Replace every  “Blog.CurrentInstance” string in the above mentioned files with the “Blog.PrimaryBlog” string 
  4. Repeat the same in all your “widget.cs”  “edit.cs” files in the “BlogEngine .NET /widget”  folder
    Replace “Blog.CurrentInstance. Cache” with the “Blog.PrimaryBlog.Cache
  5. Make the following changes in you “Global.asax.cs” file

     private static object _item = null;                   // added

      public static void Initialize(HttpContext context){

                if (_initializedAlready) {
                  
                    return;
                }
 
                lock (_SyncRoot){
                    if (_initializedAlready){
                        if(Blog.CurrentInstance.IsPrimary)    // added
                            return;
                      
                    }
                    _item = context.Items["app"];             // added
                    if(_item==null)
                       WidgetZone.PreloadWidgetsAsync(ZONENAME);
                    Utils.LoadExtensions();
 
                    Init_BundleTable();
 
                    _initializedAlready = true;
                }
            }
 

 

Then build your project to test the changes described. Everything should work fine now.

This workaround will give you a single WidgetZone rendering for all your blogs, both the primary one and all the subsequent ones, you’d wish to create them later.
 

It might not be the best solution, but at least it works smoothly, also when changing the UI culture /language.

Go ahead and good luck!

Tags:

Change language