Inconvenient SharePoint 2010 Content Query Web Part and Anonymous Access


Since the release of Microsoft Office SharePoint Server 2007 the Content Query Web Part (CQWP) has served us very well as probably the best content aggregation solution available on the SharePoint platform. And while I’ve been using it heavily for Web Content Management solutions for the last three years with great success, I got really surprised when I found out that the CQWP provided with SharePoint 2010 doesn’t work with anonymous access!

What???

Just recently Paul Galvin has stumbled upon a weird issue where the Content Query Web Part would throw an exception while aggregating contents of a Document Library when visiting the page as an anonymous user.

Content Editor Web Part throwing an exception while aggregating content of a Document Library for anonymous users.

Exactly the same page with exactly the same CQWP would work correctly for authenticated users:

The same CQWP works correctly when opened by authenticated users.

The CQWP would fail on calling the SetDocumentIconUrlAndOnClickString method. As you might’ve expected, it’s a private method so debugging it isn’t as easy as you might want it to be.

While at first I thought it was an isolated issue, related to Paul’s environment, I noticed today that I had exactly the same error on a brand new SharePoint 2010 Web Content Management solution that is about to go-live! Something had to be done about it…

The workaround

Although I’ve already knew where the issue occurs, I haven’t managed yet to isolate the reason of the issue yet and pinpoint why it’s being caused in anonymous access while everything works correctly with authenticated users. What I did manage to do, is to provide a workaround that seems to fix the issue.

I’ve found out that you can fix this issue by adding two fields to the CommonViewFields property of the CQWP:

DocumentIconImageUrl and OnClickForWebRendering, like this:

<property name="CommonViewFields" type="string">DocumentIconImageUrl;OnClickForWebRendering</property>

When you upload the edited CQWP, everything works okay again:

CQWP with two Common View Fields added works correctly for anonymous users.

I hope this is a temporary workaround only and we will see an official fix released by Microsoft soon. In the meanwhile I hope this fix will help you get the job done and you will keep using the Content Query Web Part as it’s a great piece of engineering.

Technorati Tags: SharePoint 2010,Content Query Web Part

Others found also helpful: