Base solution for your next web application
Open Closed

Extended Setting Not returned on Client Side JSON. #1875


User avatar
0
moetarhini created

I have created a new user-related setting and added it to the AppSettingProvider as new SettingDefinition. I am able to save the setting values to the database and retrieve them on the server side, but the JSON object returned from abp.setting.values does not include my custom settings.

Also, the settings seem to be not loaded when I try to access them in the _layout.cshtml, is this the correct behavior? Is there a way to access settings values in the _layout page?

Thank you


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share your setting definition ?

  • User Avatar
    0
    moetarhini created

    <cite>ismcagdas: </cite> Hi,

    Can you share your setting definition ?

    Hello,

    Thank you for your reply,

    Here is the line we are adding in the following class:

    public class AppSettingProvider : SettingProvider

    new SettingDefinition(TimeFormat.TimeFormatSettingName, ConfigurationManager.AppSettings[TimeFormat.TimeFormatSettingName] ?? "12 Hour", scopes: SettingScopes.User)
    

    and here is the full code section:

    public class AppSettingProvider : SettingProvider
       {
           public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
           {
               var defaultPasswordComplexitySetting = new PasswordComplexitySetting
               {
                   MinLength = 6,
                   MaxLength = 10,
                   UseNumbers = true,
                   UseUpperCaseLetters = false,
                   UseLowerCaseLetters = true,
                   UsePunctuations = false,
               };
    
               return new[]
                      {
                          //Host settings
                           new SettingDefinition(AppSettings.General.WebSiteRootAddress, "http://localhost:6240/"),
                           new SettingDefinition(AppSettings.TenantManagement.AllowSelfRegistration,ConfigurationManager.AppSettings[AppSettings.TenantManagement.UseCaptchaOnRegistration] ?? "true"),
                           new SettingDefinition(AppSettings.TenantManagement.IsNewRegisteredTenantActiveByDefault,ConfigurationManager.AppSettings[AppSettings.TenantManagement.IsNewRegisteredTenantActiveByDefault] ??"false"),
                           new SettingDefinition(AppSettings.TenantManagement.UseCaptchaOnRegistration,ConfigurationManager.AppSettings[AppSettings.TenantManagement.UseCaptchaOnRegistration] ?? "true"),
                           new SettingDefinition(AppSettings.TenantManagement.DefaultEdition,ConfigurationManager.AppSettings[AppSettings.TenantManagement.DefaultEdition] ?? ""),
                           new SettingDefinition(AppSettings.Security.PasswordComplexity, defaultPasswordComplexitySetting.ToJsonString(),scopes: SettingScopes.Application | SettingScopes.Tenant),
    
                           //Tenant settings
                           new SettingDefinition(AppSettings.UserManagement.AllowSelfRegistration, ConfigurationManager.AppSettings[AppSettings.UserManagement.UseCaptchaOnRegistration] ?? "true", scopes: SettingScopes.Tenant),
                           new SettingDefinition(AppSettings.UserManagement.IsNewRegisteredUserActiveByDefault, ConfigurationManager.AppSettings[AppSettings.UserManagement.IsNewRegisteredUserActiveByDefault] ?? "false", scopes: SettingScopes.Tenant),
                           new SettingDefinition(AppSettings.UserManagement.UseCaptchaOnRegistration, ConfigurationManager.AppSettings[AppSettings.UserManagement.UseCaptchaOnRegistration] ?? "true", scopes: SettingScopes.Tenant),
    
                           //User Settings
                           new SettingDefinition(DateFormat.DateFormatSettingName, ConfigurationManager.AppSettings[DateFormat.DateFormatSettingName] ?? "European", scopes: SettingScopes.User),
                           new SettingDefinition(TimeFormat.TimeFormatSettingName, ConfigurationManager.AppSettings[TimeFormat.TimeFormatSettingName] ?? "12 Hour", scopes: SettingScopes.User)
                      };
           }
       }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can only access settings defined by ABP or ABP Zero in javascript. Because ABP exposes it's settings to javascript client via this javascript include in _Layout.cshtml You have to send your setting definitions to client via result of an ActionResult or result of an ajax call.

    
    <script src="~/AbpScripts/GetScripts" type="text/javascript"></script>
    

    You should be able to access setting values in _Layout.cshtml like this.

    @SettingManager.GetSettingValue("xxx")
    

    , but user must be logged in. How do you try to access setting value in _Layout.cshtml ?