Wednesday, December 29, 2010

Anonymous user access CQWP

When trying to access Content Query Web Part with anonymous user, It failed to render. While it is working correctly with anonymous user.

I’ve found out that we 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, Text;OnClickForWebRendering,Text </property>

Other work around:

Create WebPart inherit the CQWP and add an extra column to the resulting table containing data:


public class AnonWorkingContentByQueryWebPart : ContentByQueryWebPart
{
protected override void OnInit(EventArgs e)
{
this.ProcessDataDelegate = ProcessItems;
}

protected virtual DataTable ProcessItems(DataTable data)
{
DataColumn column = new DataColumn("OnClickForWebRendering", typeof(string));
data.Columns.Add(column);

return data;
}
}

I prefer first solution

No comments: