Inconvenient SharePoint 2010 Content Query Web Part and Anonymous Access
Content Query Web Part, Customization, Inconvenient SharePoint, SharePoint 2010, WCMSince 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.
Exactly the same page with exactly the same CQWP would work correctly for 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:
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.

















August 9th, 2010 at 9:26 pm
Hi Waldek, thanks for the workaround on this. I've run into the same issue also and ended up coding a control to get around it. I'll give your fix a try instead now.
Cheers
Pete
August 9th, 2010 at 10:09 pm
@Peter: Great to hear that. I hope it's going to help you.
August 10th, 2010 at 9:03 am
Hi Waldek,
I think only OnClickForWebRendering column is needed for workaround the issue; btw great workaround! I was able to avoid the error but I used to inherit the CQWP for this; while your solution requires no additional deployment. 'Awesome' :)
Thanks
Massimo
August 19th, 2010 at 10:58 pm
I copied:
DocumentIconImageUrl;OnClickForWebRendering
from the above content and an anonymous user still can't see the content. There is no error message either just a bunch of white space.
I also tried:
OnClickForWebRendering;
and
DocumentIconImageUrl;OnClickForWebRendering;
neither works.
My cqwp is using a custom itemstyle, so I'm not sure if that is why.
Those who said they ended up coding a control, how did you go about doing that?
August 19th, 2010 at 11:00 pm
I had the proper tags around everything I tried, but they were removed when I submitted my comment
August 20th, 2010 at 6:28 am
@Tyler: are you sure that it's the same error we're talking about? In my case I had an error message. You are not seeing anything. Are you sure that the XSL that you're using has been checked in and approved? Can you confirm it by typing its URL in the browser as anonymous user?
August 20th, 2010 at 5:03 pm
OK, I ran some more tests, and I've discovered that as long as an anonymous user has Entire Site access they can see whatever the CQWP displays even without the fix described above. However, if only have access to Lists and libraries on the site they see nothing. In MOSS they were able to see the CQWPs contents with access to Lists and libraries. This also seems to be effecting summary links as well. My summary links are challenging anonymous users even though they have Lists and Libraries access.
I realize this is a different issue, but do you have any idea why list and libraries access doesn't allow anonymous users to access list item and library documents.
August 20th, 2010 at 5:56 pm
@Tyler: In my case I gave the anonymous users Entire site access and was still getting the exception mentioned in the article. I guess it all depends on the query/results that you're getting.
August 30th, 2010 at 10:20 am
Hi Waldek, first of all thanks for your great support to the SharePointers community :-).
Just a question: do you know if this workaround also solves the same error that anonymous get when a CQWP rollups images from an image or an asset library?
August 30th, 2010 at 10:35 am
@Barbara: although I haven't heard of this particular case, I would definitely give the solution a try since the images are documents as well.
September 6th, 2010 at 4:57 pm
Thanks Waldek, as you wrote, images are documents as well and your workaround saved my life!
Ciao e grazie
September 6th, 2010 at 6:05 pm
@Barbara: great to hear that! You're welcome :)
November 29th, 2010 at 9:38 am
Great Workaround Waldek the ";" is very important for this work around .. Thanks alot
you save me to be crazy from this error :)
November 30th, 2010 at 9:11 am
Thanks Waldek,
Just migrated a customer's farm and ran in to this.
Works like a charm now
I wonder how you've found this not-so-intuitive work-around.
Frank
November 30th, 2010 at 11:15 am
@Frank: it's professional secret ;)
December 30th, 2010 at 8:28 am
Hi Waldek,
I am using a CQWP to show the details of documents stored in a shared documents library of a subsite.
I have created a custom syle template in itemstyle.xsl to show the title, a custom field, document icon,modified date.
Im facing the problem where the web part throws an error for an anonymous user but works perfectly fine for a logged in user.
When i add the property mentioned to your post to the common view fields of the exported web part and import it back again. The web part is displayed for the anonymous user but the icon does not turn up. Note that the icon does not turn up even when i am logged in.
This is the XSLT i have used to display the document icon in the itemstyle.xsl
Please help me solve this or suggest a different method that i may adopt. Thanks
December 30th, 2010 at 4:53 pm
@Ganesh: As far as I know the icon field is a calculated field that works only in the scope of the list. You could retrieve the extension of the file and try to get the icon based on that but it wouldn't be foolproof since multiple extensions can be mapped to the same icon file.
January 20th, 2011 at 4:49 pm
Hi Waldek, sorry if I\'m back.
Any idea if the workaround doesn\'t work?
Same error in log:
ContentByQueryWebPart: Performance degradation due to non-guid field ref OnClickForWebRendering for a multi-list CBQ.
Error while executing web part: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.SetDocumentIconUrlAndOnClickString(SPWeb web, DataRow row, String strDefaultItemOpen, Boolean fSetDocIcon, Boolean fSetOnClick, String fileRefColumnRef, String progIdColumnRef, String fsobjTypeColumnRef, String permMaskColumnRef) at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.PreProcessForDocumentIconAndOnClickAttribute() at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.AddContentQueryData() at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.GetXPathNavigator(String viewPath) at Microsoft.SharePoint.WebPartPages.DataFormWebPart….
Thanks in advance for any suggestions,
Ciao
Barbara
ContentByQueryWebPart: Performance degradation due to non-guid field ref DocumentIconImageUrl for a multi-list CBQ.
January 21st, 2011 at 6:20 am
@Barbara: What is the scope of your CQWP: a specific list or multiples lists? Could you tell more about your query (eg. custom List Definitions/Content Types, etc.)?
January 21st, 2011 at 9:13 am
Hi waldek, sorry, you're right.
The scope is the whole site collection (excluding the root, so the second choice in th CQWP settings);
It's not a custom list definition, but a custom content type (the parent type is document); the custom content type has been created by web (not depployed via feature);
the documents in the CQWP are filtered both on the content type and on a page field value. The Page field value is a managed metadata (single value).
Thanks again
January 21st, 2011 at 9:16 am
Hi waldek, sorry, you\'re right.
The scope is the whole site collection (excluding the root, so the second choice in th CQWP settings);
It\'s not a custom list definition, but a custom content type (the parent type is document); the custom content type has been created by web (not depployed via feature);
the documents in the CQWP are filtered both on the content type and on a page field value. The Page field value is a managed metadata (single value).
Thanks again
January 21st, 2011 at 4:55 pm
Hi Barbara,
I was able to reproduce the case you described and, based on my test, using the other solution I found does fix the issue even in this case.
I posted my solution on MSDN forum some while ago:
http://social.msdn.microsoft.com/Forums/en/sharepoint2010customization/thread/90223bf3-278f-4168-b124-3413489b936a
Hope this helps
January 25th, 2011 at 1:03 pm
Hi Massimo,
thanks for your contribution as well.
I've got good news for everybody: reading between the lines of the october CU, I've discovered that Microsoft solved the problem. In the KB description they talk about Documen Center (The content-based query web part in the Document Center page no longer displays the document files in SharePoint Server 2010. This issue occurs when you are using an anonymous user for accessing the Document Center page), but I've done some test and now the anonymous got the CQWP working. :-)
January 25th, 2011 at 4:43 pm
@Barbara: Great stuff! Thanks for getting back on this :)
February 2nd, 2011 at 1:24 pm
It works for me, THANK YOU SO MUCH!
Just one thing: punctuation is crucial, I paste the line which works for me:
DocumentIconImageUrl;OnClickForWebRendering;
April 2nd, 2011 at 6:08 pm
Microsfot October CU contains the fix for anonymous access with CQWP.
April 19th, 2011 at 4:44 pm
Thank you so much Waldek! I have been struggling with this issue for 2 days now. I thought it might have been something wrong with my content types. Guess not! thanks!
April 19th, 2011 at 4:45 pm
@Ping have you tried out the october CU?
April 20th, 2011 at 3:36 pm
@Brian: Not yet, although I've heard it solves this issue.
May 11th, 2011 at 11:02 am
Thanks Waldek
Works like a charm!
June 9th, 2011 at 7:02 pm
Hi Waldek,
This fix worked.
But the page I used it on had several other CQWPs and they became uneditable and fully chromed after inserting the fixed CQWP.
I removed the fixed WP but the affect on the other web parts persists.
This also cascades to other pages once they are edited.
Do you know how I can back out the fix?
Thanks,
Graham
June 10th, 2011 at 7:36 am
@Graham: I haven't experienced what you described myself, so it's hard to say. What I've heard though is that the October CU contains a solution for the CQWP issue so you might want to try that. Remember check it in a test environment first before patching the production!
June 10th, 2011 at 7:00 pm
Thanks Waldek
I'm guessing that my problem had something to do with having 6 CQWPs on the same page.
I'm on a dev box so no big deal.
Cheers
June 14th, 2011 at 5:01 pm
Thank you very much, Waldek. Your step-by-step solution fixed my problem completely. Great find!
July 11th, 2011 at 9:53 pm
A little digging can go a long way. Thanks for the workaround Waldek, life saver :)!
September 5th, 2011 at 6:24 pm
I have been trying for weeks to figure out why this does not work – and then I found your answer. Thank you very much, you genius