SaaS CMS has officially launched! Learn more now.

Anonymous rating



I have a question about anonymous ratings. It seems it is not possible to rate more than once per user which is understandable. In order to rate anonymously one has to rate with the user Anynymous which means that this can only be done once. Is there any way around this? I have tried using null instead of author when creating a ratings object but this is not allowed. See the code below.

            if (userId != "") CommunitySystem.CurrentContext.DefaultSecurity.GetUser(Convert.ToInt32(userId));

            IRating rater = new Rating(answer, Convert.ToDouble(vote), userId == "" ? null : user.GetAuthor());


We are running EPiServer Community 3.2.5 with episerver CMS 5.2

Sep 21, 2010 9:45

..and to make anonymous ratings the following code was used

IUser user = CommunitySystem.CurrentContext.DefaultSecurity.GetUserByUserName(
IAuthor theAuthor = AuthorHandler.GetAnonymousAuthor(user, PageReference.StartPage.SiteSettings().GetProperty<string>("AnonymousUser"));

Sep 21, 2010 10:16

Sounds like you need a GuestAuthor. How to stop users from posting multiple ratings is a different problem, perhaps just use a cookie to store what entities the guest has already rated.

Sep 21, 2010 11:33

What do you mean by GuestAuthor?

We already have a cookie to prevent users from rating several times. The problem is that when not logged in it is supposed to be possible to rate once per anynymous "computer". However it is only possible to add one rating per user in Relate+ and since anonymous author is a based on a user only the first anonymous user can rate. When rating a second time for the same user in Relate the previous rating is over written. What we want is to be able to vote several times anonymously, once per computer. The once per computer part is already solved by our cookie.

How can I solve this?

Sep 21, 2010 12:57

There are several implementations of the IAuthor interface, UserAuthor is only one. Another is GuestAuthor, which sounds perfect for your situation. You have declared your "theAuthor" as an IAuthor, so I assume you can use the GuestAuthor instead, like so: IAuthor theAuthor = new GuestAuthor([any string you like here]);


Sep 21, 2010 13:25

Thanx, that worked like a charm! However the code is ugly.. I would appreciate an empty constructor for better usability since the key probably is the email or the email in conjunction with the name.

string uniqueVisitor = DateTime.Now.Ticks.ToString();
guestAuthor = new GuestAuthor(uniqueVisitor,String.Format("{0}",uniqueVisitor));


Edited, Sep 21, 2010 16:20
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.