Fixing cannot load dashboard issues on BlogEngine.NET using sub blog aggregation

As I discovered during my BlogEngine upgrade, there is an effort within the project team to focus the codebase on three possible usage models on any given BlogEngine server instance:

  • Single blog with a user – a personal blog (default)
  • Single blog with many users – a team/company blog
  • Many blogs each with a single user – a set of related blogs that can be agregated togther

I needed the third option, problem was in its history our blog has been both of the other two types, so I have multiple user accounts for each blogs, and login usernames are repeated between individual blogs on the server.

This is not fundamentally an issue for a server running in the third mode, except on the primary blog that is setup to provide agregation of all the other blogs.  Even here, on a day to day basis, it is not an issue either, basic post RSS aggregation is fine. However, when you login as an administration user and try to access the dashboard you get the error

1Item has already been added. Key in dictionary: 'displayname' Key being added: 'displayname'

The workaround I have used in the past was to temporarily switch off blog aggregation whenever I needed to access the primary blog dashboard – not the best solution.

After a bit of investigation of the codebase I found that this issue is due to the fact we had users  called ‘admin’ on the primary and all the child blogs. The fix I used was a bit of SQL to do some user renaming from ‘admin’ to ‘adminblogname’ . I needed to rename the username in a few tables.

AS USUAL BEWARE THIS SQL, MAKE SURE YOU HAVE A BACKUP BEFORE YOU USE IT, IT WORKS FOR ME BUT I MIGHT HAVE MISSED SOMETHING YOU NEED

 1  
 2update p  
 3set p.SettingValue = concat (p.SettingValue , ' ', b.BlogName)  
 4from be\_Profiles p  
 5    inner join be\_Blogs b on  
 6        b.BlogID = p.BlogId  
 7where  
 8SettingName ='displayname' and  
 9SettingValue = 'admin'; 
10
11update p  
12set p.UserName = concat (p.UserName , b.BlogName)  
13from be\_Profiles p  
14    inner join be\_Blogs b on  
15        b.BlogID = p.BlogId  
16where  
17username= 'admin';
18
19 
20
21update u  
22set u.UserName = concat (u.UserName , b.BlogName)  
23from be\_Users u  
24    inner join be\_Blogs b on  
25        b.BlogID = u.BlogId  
26where  
27username = 'admin';
28
29 
30
31update r  
32set r.UserName = concat (r.UserName , b.BlogName)  
33from be\_UserRoles r  
34    inner join be\_Blogs b on  
35        b.BlogID = r.BlogId  
36where  
37username = 'admin';

This is not a problem specific to admin users, any username duplication will cause the same error. This basic SQL script can be modified to fix any other user accounts you might have username clashes on.

Once this SQL was run I was able to login to the dashboard on the primary blog as expected.