EBE Deleting a Theme Causes Errors

Topics: Enhanced Blog Edition
Oct 21, 2008 at 7:55 PM
First of all, the Community Kit rocks and many thanks to those who have contributed to its success.

I've create a Feature that deploys a series of custom themes and I've written code so if my Themes Feature is uninstalled, it will set the theme back to "Default" (using SPWeb.WebProperties).  Unfortunately, the current theme is also stored in the user's cookie so if they return to the site, the Master Page is set to the theme which no longer exists and an error occurs.  (The cookie lasts for two years, so it won't simply time out anytime soon.)

I can't see any way to avoid this problem.  The only solution I can think of is to add an HTTP Module to catch the error and have it redirect back to the page with the new theme specified.  This seems like a pretty big hack, though.

Any thoughts would be greatly appreciated!
Developer
Oct 21, 2008 at 8:25 PM
Are you sure it's the cookie that's doing it?  I've noticed when setting themes programmatically, you have to set it twice in order to flush the theme cache.  So I make a  habit of doing something like:

      // In order to flush the theme cache, we call this method twice. 
      // If there is no theme, it doesn't matter that we set it to none first
      string theme = (string)SiteConfig["ThemeName"] ?? "";  // Coalesce possible null to an empty string
      web.ApplyTheme("none");
      if (theme != "")  // If we're resetting the branding, it should have been set to "none" in the configuration.
        web.ApplyTheme(theme);

Note that the above snippet isn't part of CKS:EBE, it's from one of my other projects.

Regards,
Mike Sharp
Oct 21, 2008 at 9:53 PM

Thanks for the reply, Mike. I’m not sure that we are talking about the same themes. I’m referring to the Themes used by the Modular Themes Framework (MTF) provided in the Enhanced Blog Edition which I believe is completely separate from the standard SharePoint Theme infrastructure. It looks like your code is for standard SharePoint Themes (unless there’s a relationship that I’m unaware of).

Bill

Developer
Oct 22, 2008 at 3:17 AM
Sorry, I misunderstood your question.  I thought you were resetting to the SharePoint default...

Why couldn't you modify the BlogContext.BlogThemes getter to check to see if the theme exists? 


public string BlogTheme
{
    get
    {
        if (!string.IsNullOrEmpty(_currentTheme)) return _currentTheme;

 

        if (!string.IsNullOrEmpty(HttpContext.Current.Request["theme"]) && BlogContext.Current.Settings.ThemeSelectorEnabled) return HttpContext.Current.Request["theme"];

        HttpCookie oCookie = HttpContext.Current.Request.Cookies["ebeBlogTheme-" + SPContext.Current.Web.Url];

        _currentTheme = (oCookie == null) ? "" : oCookie.Value;
       
        // Check here to see if theme exists, set _currentTheme to null or empty if not

        if (string.IsNullOrEmpty(_currentTheme))
            _currentTheme = Settings.BlogTheme;

        if (string.IsNullOrEmpty(_currentTheme)) _currentTheme = "Default";

        return _currentTheme;
    }
}


Regards,
Mike Sharp
Oct 22, 2008 at 3:21 PM

Yes, I was hoping to avoid customizing the original Community Kit source code, but that may be my best option. Even a session cookie would work fine instead of a permanent one.

Thanks for the suggestion!

Developer
Oct 22, 2008 at 5:05 PM
It seems like a reasonable approach; perhaps Vince (TheKid) will see this thread and add it to the CKS.  You might write a post in the Issue Tracker.   Attempting to set a theme that doesn't exist based on a cookie seems like a real possibility, which would make the error behavior a bug. 

Regards,
Mike Sharp