appsettings

Automatically set appsettings.json for dev and release environments in asp.net core?

自闭症网瘾萝莉.ら 提交于 2019-11-27 17:58:10
I've defined some values in my appsettings.json for things like database connection strings, webapi locations and the like which are different for development, staging and live environments. Is there a way to have multiple appsettings.json files (like appsettings.live.json , etc, etc) and have the asp.net app just 'know' which one to use based on the build configuration it's running? You may use conditional compilation: public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true,

how to change .NET user settings location

巧了我就是萌 提交于 2019-11-27 17:49:42
问题 By default settings are stored at: C:\Documents and Settings\\Local Settings\Application Data\<Project Name> How can I change this path to application directory. I also don't want to have different files for different users. How make the settings global? I tried to change the scope of the settings to "application" but then I cannot change them at runtime. 回答1: Using the default built-in behavior you can't! Q: Why is the path so obscure? Is there any way to change/customize it? A: The path

Read appsettings.json from a class in .NET Core 2

浪子不回头ぞ 提交于 2019-11-27 17:39:06
问题 I need to read a list of properties from appsettings.json file (section: placeto ) in a business class, but I haven't been able to access them. I need these properties to be public. I add the file in the Program class: This is my appsettings.json : { "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Warning" } }, "placeto": { "login": "fsdfsdfsfddfdfdfdf", "trankey": "sdfsdfsdfsdfsdf" } } 回答1: First : Use the default in program.cs for it already adds Configuration: public class

How do you put environmental variables in web.config?

陌路散爱 提交于 2019-11-27 17:29:55
问题 I am currently Following these tutorials, and I am wanting to call the clear text string from Azure's Application Settings for Web Apps. I am under the impression that environmental variables are used for non-config files. However, I am wanting to use the same methodology for web.config files. <connectionStrings configSource="/config/ConnectionStrings.config"> <add name="DefaultConnection" connectionString="@Environment.GetEnvironmentalVariable('SQLAZURECONNSTR_DefaultConnection')"

Azure Application Settings not overriding my appsettings.json file values

守給你的承諾、 提交于 2019-11-27 17:19:29
问题 I have tried adding DefaultConnection from my appsettings.json file to Azure's Application Settings but Azure will not override the connection string. Any article or blog I can find states that all I should need to do is add the connection string name as it states in the appsettings.json file and Azure should do the rest (e.g. https://tehremo.wordpress.com/2016/10/07/override-connection-strings-app-settings-in-asp-net-core-and-azure-app-service/) however when the application is published it

Find current country from iPhone device

你。 提交于 2019-11-27 17:10:00
I have to get the current country in the iPhone settings. Can anyone tell me how to get the current country in iPhone application. I have to use the current country for parsing the RSS feed in which I need to pass the current country. Please help me out to find the country . Thanks in advance. kennytm To find the country of the user's chosen language: NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc. In Swift: let currentLocale =

How can I set application settings at install time (via installer class)

随声附和 提交于 2019-11-27 16:47:14
问题 I have a Visual Studio setup project that has an Installer class. In the installer class I set a setting as follows: MessageBox.Show(Properties.Settings.Default.MySetting); Properties.Settings.Default.MySetting = "Foo"; Properties.Settings.Default.Save(); MessageBox.Show(Properties.Settings.Default.MySetting); The problem is that even though I know that this code is being executed (I am doing other stuff), the setting is never set!! The message boxes do suggest that the value is being set,

Can someone provide a quick App.config/Web.config tutorial?

ぐ巨炮叔叔 提交于 2019-11-27 15:08:38
问题 I've used these two configuration files many times before, but I've never taken the time to fully understand how they really work. As most people do, I understand the basics in how to call WebConfigurationManager.AppSettings["key"] to get config values. Here are some questions I came up with: What happens when you reference a configuration value within a class library, and the library is part of a bigger solution? Does the app.config need to be copied to the output directory in order for the

Get the App.Config of another Exe

孤者浪人 提交于 2019-11-27 14:30:46
问题 I have an exe with an App.Config file. Now I want to create a wrapper dll around the exe in order to consume some of the functionalities. The question is how can I access the app.config property in the exe from the wrapper dll? Maybe I should be a little bit more in my questions, I have the following app.config content with the exe: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="myKey" value="myValue"/> </appSettings> </configuration> The question is how to

Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App

怎甘沉沦 提交于 2019-11-27 11:54:05
I have the following class in NET Core2.0 App. // required when local database does not exist or was deleted public class ToDoContextFactory : IDesignTimeDbContextFactory<AppContext> { public AppContext CreateDbContext(string[] args) { var builder = new DbContextOptionsBuilder<AppContext>(); builder.UseSqlServer("Server=localhost;Database=DbName;Trusted_Connection=True;MultipleActiveResultSets=true"); return new AppContext(builder.Options); } } This is required in Core 2.0 with migration when Database does not exist and has to be created when you run update-database . Unable to create