Specify enviroment settings in Paas Portal and fetch them in the code

Vote:
 

Hi, we have creating an microsoft exchange account used to send emails out to users. As we don't want to store the username and password of the exchange account in appsettings.json, we want to save it in the PaaS Portal. After we save the settings in the Paas Portal, how can we retrieve the values for username and password and use those values in the code?

#307677
Edited, Aug 30, 2023 12:16
Vote:
 
_configuration.Get<string>("MySecretKey", "Fallback value");

docs

#307686
Aug 30, 2023 16:23
Tam Duc Ha Vo - Aug 31, 2023 9:09
Seems to be a problem with the Get method. I've explained it in the post below :)
Vote:
 

private readonly IWebHostEnvironment _webHostingEnvironment;
        private readonly IConfiguration _configuration;

        public Startup(IWebHostEnvironment webHostingEnvironment, IConfiguration configuration)
        {
            _webHostingEnvironment = webHostingEnvironment;
            _configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCmsCloudPlatformSupport(_configuration);
            var connectionString = _configuration.GetConnectionString("EPiServerDB"); // Retrieve connection string here
            services.AddCustomServices(); // Extension method to collect all custom services

            IConfigurationSection smtpSection = _configuration.GetSection("EPiServer:Smtp:Network");

            services.Configure<SmtpConfiguration>((config) =>
            {
                config.Host = smtpSection["Host"];
                config.Port = int.Parse(smtpSection["Port"]);
                config.Username = _configuration.Get<string>("UserName", "Fallback");
                config.Password = smtpSection["Password"];
                config.EnableSsl = bool.Parse(smtpSection["UseSsl"]);
            });
The line in bold throws an error: 
1. No overload for method Get takes 2 arguments

2. Cannot resolve method Get(string, string), candidates are etc...

#307726
Aug 31, 2023 9:09
Vote:
 

I guess Mark meant

_configuration.GetValue<string>("abc", "xyz");

#307728
Aug 31, 2023 9:25
Tam Duc Ha Vo - Aug 31, 2023 9:31
Aha, thank you. So "abc" is the name of the app setting, while "xyz" is just a fallback value?
Quan Mai - Aug 31, 2023 9:48
yes. basically what Mark posted, just GetValue instead of Get
Tam Duc Ha Vo - Aug 31, 2023 9:49
Alright, thank you!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.