Building Custom WCM Sites with SharePoint 2010: #3 Allow Anonymous Ratings

Lesson 3: Learn how to enable anonymous users to rate

Todd Baginski

September 30, 2011

3 Min Read
ITPro Today logo in a gray background | ITPro Today

Lesson 3: Learn How to Allow Anonymous Users to Rate Content

More often than not, when you create a new website nowadays, one requirement is the need to let users rate content in the website. SharePoint 2010 ships with functionality that allows users to rate any list item in a SharePoint website, such as pages, videos, pictures, audio clips, or anything else you can store in a SharePoint list.

However, this ratings functionality is designed to work only for users who are logged on to the SharePoint website.

There are two ways to implement ratings functionality in public-facing SharePoint websites.

The first way is to require users to sign in before they can rate an item. An example of this scenario is the SharePoint marketing website.

In the screenshot below, the rating for the video is displayed in the lower right of the screen. When users aren’t signed in, the Sign In link appears below the rating control.





When users click the Sign In link, they’re redirected to the page where they can sign in with their Windows Live IDs. After they sign in, they’re redirected back to the page where they started (see the next screenshot below), and the ratings control is enabled.


The second approach is to create your own ratings control that allows anonymous users to rate content. The Visio marketing website implements this approach.

The anonymous ratings Web Part created for this website stores ratings in a custom hidden SharePoint list. The screenshot below shows sample data in the hidden list that stores the rating data.



The anonymous rating Web Part uses the SPSecurity.RunWithElevatedPrivileges method to create and update the list items that store the rating data.

AJAX is used to submit ratings and retrieve them without refreshing the entire Web page. The JQuery library is used to manipulate the CSS and associated elements in the Web Part.

When Gary Lapointe and I built the anonymous rating Web Part, we used the same CSS as the out-of-the-box rating control so that our anonymous rating Web Part looked like the out-of-the-box ratings control that comes with SharePoint (see the screenshot below).



In the Visio site, these out-of-the-box CSS styles are overridden to create the look you see in the next  screenshot below:




The rating Web Part uses cookies to determine if the user viewing the page has previously rated the item.  Obviously, this approach is less fool-proof than the other method because a user can delete their cookies and rate the item again. 

However, this approach does allow anonymous users to rate items in SharePoint without logging in.

 For this Web site, the issues related to one person possibly rating an item over and over if they deleted their cookies was not considered a big enough risk to require the users to sign in. 

The screen shot below illustrates what the anonymous rating Web Part looks like after a user has rated the item.


See Lesson 2 from Todd Baginski: Use the Content by Query Web Part
See Lesson 1 from Todd: Pay Attention to Page Size
See the back story on how Todd learned this.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like