Try our conversational search powered by Generative AI!

VisitorGroups Criterion values not persisted?


Hi, I am creating a custom SelectionCriterion (just for fun) for use with VisitorGroups, on EPiServer CMS (Product Version: 8.11.0, File Version on EPiServer.dll).

It displays seemingly correctly in the EPiServer GUI, and no errors when cliking the Save button when creating a new visitor group.

However, if I go away from the page and then return to the settings for the visitor group, the values which I selected are (seemingly) no longer set.

So did the settings get saved or not? How can I know?

If it's just a display problem, then that's not so bad, except it would be nice to be able to go in and see what the settings are.

Please help!

This is the model:

    public class BeenMissingYouCriterionSettings : CriterionModelBase
        [Range(1, 999)]
        public int Number { get; set; }

        /// Text for enum members are set in lang file: /Resources/LanguageFiles/Enums.xml
        [DojoWidget(SelectionFactoryType = typeof(EnumSelectionFactory))]
        public PropertyTimeSpanControl.TimeUnit Unit { get; set; }

        public override ICriterionModel Copy()
            return ShallowCopy();

And here's the SelectionCriterion:

       Category = "Time and Place Criteria",
       DisplayName = "I've Been Missing You",
       Description = "Returns true if more than configured timeunits since last login.")]
    public class BeenMissingYouCriterion : CriterionBase
        public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
            var user = Membership.GetUser();
            switch (Model.Unit)
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Minute:
                    return user?.LastLoginDate.AddMinutes(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Hour:
                    return user?.LastLoginDate.AddHours(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Day:
                    return user?.LastLoginDate.AddDays(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Week:
                    return user?.LastLoginDate.AddDays(Model.Number * 7).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Month:
                    return user?.LastLoginDate.AddMonths(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Undefined:
                    return false;
                    return false;
Sep 23, 2015 11:18

Hello Svein

At first glance your code looks OK. I can only think that perhaps something has gone wrong with the TimeUnit property on the model. Have you tried creating a more simple version just using strings? 

You should also check out the console to look for any javascript errors that are not being displayed to end users when the criteria loads.

I recently posted a simple set of criteria for cookies so perhaps you could start with mine and refactor until you find the issue?


Sep 23, 2015 15:50


[DojoWidget( DefaultValue = 1), Required, Range(1, 999)]
public int Number { get; set; }
Edited, Sep 23, 2015 16:16

Thanks for the help (long time). I appreciate it! But unfortunately I was diverted into something else, so I never got to fix this, and now I don't even have the code any more. So I guess theres only one word to say: Sorry!

Nov 24, 2017 8:54
* 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.