question

dml5-3953 avatar image
0 Votes"
dml5-3953 asked singhh-msft edited

Azure Feature Flags - Net Framework

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://docs.microsoft.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
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@dml5-3953, thank you for reaching out to us. I suspect that the missing UserId in the TargetingContext might be the issue. Further, this official sample using .NET 5.0 works fine for me. Can you try the sample and let me know if it works for you?




1 Vote 1 ·

We are not using user names. Just groups. And the groups are not email addresses. Do they have to be emails with users in the format a@b.com or can they be a business name, etc?

I am positive that NET CORE or NET 5 would work but the application version can't be changed.

I will look at the NET 5 version anyway. Thanks.

0 Votes 0 ·

@dml5-3953 , just checking in to see if you got a chance to check my response.

0 Votes 0 ·

@dml5-3953 , just checking in to see if you got a chance to check my response.

0 Votes 0 ·
singhh-msft avatar image
0 Votes"
singhh-msft answered singhh-msft edited

@dml5-3953, 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.






· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@dml5-3953 , just checking in to see if you got a chance to check my response.

0 Votes 0 ·

@dml5-3953 , just checking in to see if you got a chance to check my response.

0 Votes 0 ·

@dml5-3953 , do share your valuable feedback of your experience with us!






0 Votes 0 ·
dml5-3953 avatar image
0 Votes"
dml5-3953 answered singhh-msft commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@dml5-3953 , I will pass on the feedback. Just for clarification, can TargetingContext not help as it matches both UserId and Groups and returns the result?


0 Votes 0 ·