How can I programatically assign a visitor group to a user from C#?
Hi Dylan, have you read about how to create your own visitor group in the developer guide? Just asking because you are talking about assigning visitor to a group instead of evaluating visitor for some criteria X.
I'm assuming the visitors are anonymous(?) users (not signed in so that you would actually know who they are). So I think in your case the simplest client side approach would be to create a cookie when the user for example starts the loan application and you create a cookie for example with value "prospect" on the client side and depending the process remove the cookie when loan application is submitted or set some other state value that you can later use.
Then implement your own visitor group criteria where you check if the user has the cookie with value "prospect" so then you know you can have these users in the "prospect" visitor group (that you create with the criteria you implement). If your process can have differnt states then you propably implement the visitor group criteria in a way that editor (visitor group admin member) can create different actual visitor groups with the criteria.
Hope this helps or if I understod your question wrongly then please clarify your needs a bit more.
I think you are viewing the visitor groups a bit backwards. A user is never directly assigned a visitor group. Instead, whenever a particular visitor group is required (an IsInRole call is made) the logic for that particular type of visitor group will be evaluated and a bool will be returned, indicating if the user is part of that group. That value is not persisted, instead the logic is re-run for each check. And it has to be as for the next time that visitor group is evaluated for the same user, it might yield another result (consider for example the time and place visitor group).
For your scenario, one approach could be to store a value in any kind of data store when the Ajax request is made. The value would be that the current user has fulfilled the scenario, in this case left without finishing. You could then make your own custom visitor group which checks the stored data and makes a decision if a particular user is a member of the group.
Here is an example of a custom visitor group, https://world.episerver.com/documentation/developer-guides/CMS/personalization/example-create-your-own-visitor-group-criteria/.
Edit: Or what Antti just said :)
I will follow the cookie approach, seems like a good way to go.