November Happy Hour will be moved to Thursday December 5th.

Checking if current user is in visitor group

Vote:
 

Hi!

I'm trying to determine if a visitor belongs to a visitor group from code. It returns false everytime when I use geolocation, but works when I tested a span of time. I've checked so virtualroles replaceprincipal is set to true.

This is my code:

var visitorGroups = new VisitorGroupStore(DynamicDataStoreFactory.Instance).List().OrderBy(v => v.Name);

foreach (var group in visitorGroups)

            {

bool isInRole = newVisitorGroupHelper().IsPrincipalInGroup(PrincipalInfo.CurrentPrincipal, group.Name);

            }

Any ideas about what I'm doing wrong?

/Peter

#71639
May 24, 2013 17:38
Vote:
 

Isn't this just a problem with geolocation?

Gelocation uses your IP address against a known database, by default stored at C:\Program Files (x86)\EPiServer\Framework\6.2.267.1\Geolocation\GeoLiteCity.dat

If you are testing on your local machine this can often return false as your IP address is local;such as 127.0.0.1 or something in the 192.168.xxx range, also sometimes production environment setups behind load balancers don't correctly pass through the originating client IP address meaning geolookup doesn't work correctly.

Why don't you try logging out the incoming IP address to check its value - see http://stackoverflow.com/questions/1907195/how-to-get-ip-address

 

 

#71642
May 24, 2013 19:57
Vote:
 

Thanks, I'll try that! As soon as we get the production servers I can test this more thoroughly.

Btw. Do you know how to mark a post as answered in the new forum?

#71675
Edited, May 27, 2013 11:41
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions 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.