Azure Feature Flags - Net Framework

dml5 21 Reputation points
2021-06-05T21:03:01.81+00:00

I am using Azure Feature Filters with the Net Framework 4.8. I created a Targeting Feature Filter and entered 1 group name which I call from my application. It should return true if the group is found and false if not found. I followed this tutorial to create the flag and connection: https://video2.skills-academy.com/en-us/azure/azure-app-configuration/quickstart-feature-flag-dotnet. And added a ContextualTargetingFilter:

services.AddSingleton<IConfiguration>(_configurationroot).AddFeatureManagement().AddFeatureFilter<ContextualTargetingFilter>();

Now when I call await GetFeatureToggleAsync("FeatureFlagName", GroupValue) it always returns true. I swear this worked last week and returned false when the groupvalue was not a match. What am I doing wrong?

public static async Task<bool> GetFeatureToggleAsync(string featureToggle, string group)  
{  
  
  using (ServiceProvider serviceProvider = _services.BuildServiceProvider())  
  {  
    IFeatureManager featureManager =   
    serviceProvider.GetRequiredService<IFeatureManager>();  
  
    var context = new TargetingContext  
    {  
      Groups = new List<string>() { group }  
    };  
    return await featureManager.IsEnabledAsync(featureToggle, context);  
  }  
}  
Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
215 questions
{count} votes

Accepted answer
  1. singhh-msft 2,431 Reputation points
    2021-06-08T11:47:31.81+00:00

    @dml5 , thank you for reaching out to us. The first thing to do for setting up Feature Management is to map users and groups in whatever authentication method is being used for users/groups, specifically to create TargetingContext instances for users. A TargetingContext contains the user id and list of groups to which the user belongs. This information is used to position the current user in the audience that has been configured.

    One way to build a TargetingContext is to get it from the logged in user's context by getting the User.Identity property:

    var userClaims = User.Identity as System.Security.Claims.ClaimsIdentity;  
    

    I tested on my system and using this code but removing UserId in TargetingContext and it gives me inconsistent results as per configuration. So, I would recommend you to use UserId and Groups both to get reliable results.

    Check out this article for a better understanding of implementation in .NET Framework by going through the logic and explanations in ASP.NET Core 3.1 MVC app (note that it is just for understanding the concepts). Further, do check out official documentation on Feature Flags.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


1 additional answer

Sort by: Most helpful
  1. dml5 21 Reputation points
    2021-06-09T15:40:38.24+00:00

    Thanks. It appears it would not be possible to use the Feature Flags in the way that was intended. It is unfortunate that there isn't another feature filter option (other than TargetingContext) that matches the string in either or both of users or groups.