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.


Possibly related posts

36 Responses to “Inconvenient SharePoint 2010 Content Query Web Part and Anonymous Access”

  1. Peter Says:

    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

  2. Waldek Mastykarz Says:

    @Peter: Great to hear that. I hope it's going to help you.

  3. Massimo Prota Says:

    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

  4. Tyler Bithell Says:

    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?

  5. Tyler Bithell Says:

    I had the proper tags around everything I tried, but they were removed when I submitted my comment

  6. Waldek Mastykarz Says:

    @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?

  7. Tyler Bithell Says:

    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.

  8. Waldek Mastykarz Says:

    @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.

  9. Barbara Says:

    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?

  10. Waldek Mastykarz Says:

    @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.

  11. Barbara Says:

    Thanks Waldek, as you wrote, images are documents as well and your workaround saved my life!
    Ciao e grazie

  12. Waldek Mastykarz Says:

    @Barbara: great to hear that! You're welcome :)

  13. Qassem Says:

    Great Workaround Waldek the ";" is very important for this work around .. Thanks alot
    you save me to be crazy from this error :)

  14. Frank Says:

    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

  15. Waldek Mastykarz Says:

    @Frank: it's professional secret ;)

  16. Ganesh Says:

    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

  17. Waldek Mastykarz Says:

    @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.

  18. Barbara Says:

    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.

  19. Waldek Mastykarz Says:

    @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.)?

  20. Barbara Says:

    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

  21. Barbara Says:

    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

  22. Massimo Prota Says:

    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

  23. Barbara Says:

    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. :-)

  24. Waldek Mastykarz Says:

    @Barbara: Great stuff! Thanks for getting back on this :)

  25. Olivier Says:

    It works for me, THANK YOU SO MUCH!

    Just one thing: punctuation is crucial, I paste the line which works for me:

    DocumentIconImageUrl;OnClickForWebRendering;

  26. Ping Says:

    Microsfot October CU contains the fix for anonymous access with CQWP.

  27. Brian Bolton Says:

    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!

  28. Brian Bolton Says:

    @Ping have you tried out the october CU?

  29. Waldek Mastykarz Says:

    @Brian: Not yet, although I've heard it solves this issue.

  30. Nazeer Alper Says:

    Thanks Waldek

    Works like a charm!

  31. Graham Says:

    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

  32. Waldek Mastykarz Says:

    @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!

  33. Graham Says:

    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

  34. Brandon Anderson Says:

    Thank you very much, Waldek. Your step-by-step solution fixed my problem completely. Great find!

  35. Pranav Kothare Says:

    A little digging can go a long way. Thanks for the workaround Waldek, life saver :)!

  36. Alan Says:

    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

Leave a Reply

Security Code:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2012 Waldek Mastykarz

Creative Commons License