Open Closed

New Feature checker #8878


User avatar
0
jmalla.cp created
  • ABP Framework version: v6.0.1

  • UI Type: MVC

  • Database System: EF Core (PostgreSQL)

  • Tiered (for MVC) or Auth Server Separated (for Angular): Tired

  • Exception message and full stack trace:

  • Steps to reproduce the issue:

Hi,

I'm trying to configure a new feature with FeatureDefinitionProvider like this:

public class WebAppFeatureDefinitionProvider : FeatureDefinitionProvider
{
    public override void Define(IFeatureDefinitionContext context)
    {
        var myGroup = context.AddGroup("WebApp");

        myGroup.AddFeature(
            WebAppFeatures.LoginEnabled,
            defaultValue: "true",
            displayName: L("LoginEnabled"),
            valueType: new ToggleStringValueType()
        );

        myGroup.AddFeature(
            WebAppFeatures.BackgroundJobEnabled,
            defaultValue: "true",
            displayName: L("BackgroundJobEnabled"),
            valueType: new ToggleStringValueType()
        );
    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<WebAppResource>(name);
    }
}

These two features are enabled to allow changes to the value from the web frontend. I can change the value, and it is also updated in the database.

image.png

But when I try to get the value, like this:

var backgroundJobEnabled = await _featureChecker.GetOrNullAsync(WebAppFeatures.BackgroundJobEnabled);
var loginEnabled = await _featureChecker.GetOrNullAsync(WebAppFeatures.LoginEnabled);

The value always is true

image.png

Can someone helps me?

Thanks


5 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    I tried to reproduce the problem but I could not. BackgroundJobEnabled should be false, but this value may also be coming from the cache. In order to determine this situation, can you confirm whether you see the value in the database when you close and open your Redis server or restart the application?

  • User Avatar
    0
    jmalla.cp created

    Hi,

    After restarting the application, the problem persists

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    I created a project with 6.0.1 and tried it with the codes you mentioned, but I could not reproduce your problem.

    Screenshot 2025-02-28 at 10.48.11.png

    Screenshot 2025-02-28 at 10.48.20.png

    In the picture below you can see where I set this value:

    Screenshot 2025-02-28 at 10.57.36.png


    In your case, in which project is WebAppFeatureDefinitionProvider defined and where did you set this value? Also, in which project is SyncActiveFarmsWorker defined?

  • User Avatar
    0
    jmalla.cp created

    Yes, you are right.

    Sorry, I had changed the value in the wrong place on the web, in the Standard Editions Features. Now, I have changed the value in "Manager Host Features" and that's correct.

    Please, cloud you tell me how I can block the login, using the feature loginEnabled and if role is not admin?

    Thanks

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Yes, you are right.

    Sorry, I had changed the value in the wrong place on the web, in the Standard Editions Features. Now, I have changed the value in "Manager Host Features" and that's correct.

    I am glad it is working.

    Please, cloud you tell me how I can block the login, using the feature loginEnabled and if role is not admin?

    Normally, you should to open a separate ticket for this, but if I need to give brief information, you can override the OnPost method of the Login page model and add the logic you want before calling base.OnPost.

    Here are the related contents:


    Closing the issue. Feel free to create a new issue if you have further questions.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 13, 2025, 04:08