Find current country from iPhone device

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 = NSLocale.currentLocale() let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String If you want to find the country code of … Read more

Reading dll.config (not app.config!) from a plugin module

You will need to load the x.dll.config (with the Configuration API) yourself. All the automatic file handling (including the .Settings) is all about machine.config/y.exe.config/user-settings. To open a named config file: Reference System.Configuration.dll assembly. Using System.Configuration Create code like: Configuration GetDllConfiguration(Assembly targetAsm) { var configFile = targetAsm.Location + “.config”; var map = new ExeConfigurationFileMap { ExeConfigFilename … Read more

Encrypting appSettings in web.config

Encrypting and Decrypting Configuration Sections (ASP.NET) on MSDN Encrypting Web.Config Values in ASP.NET 2.0 on ScottGu’s blog Encrypting Custom Configuration Sections on K. Scott Allen’s blog EDIT: If you can’t use asp utility, you can encrypt config file using SectionInformation.ProtectSection method. Sample on codeproject: Encryption of Connection Strings inside the Web.config in ASP.Net 2.0

how to get value from appsettings.json

So there are really two ways to go about this. Option 1 : Options Class You have an appsettings.json file : { “myConfiguration”: { “myProperty”: true } } You create a Configuration POCO like so : public class MyConfiguration { public bool MyProperty { get; set; } } In your startup.cs you have something in … Read more

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

STEP 1: Include the following in OnConfiguring() protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile(“appsettings.json”) .Build(); optionsBuilder.UseSqlServer(configuration.GetConnectionString(“DefaultConnection”)); } STEP 2: Create appsettings.json: { “ConnectionStrings”: { “DefaultConnection”: “Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true” } } STEP 3: Hard copy appsettings.json to the correct directory Hard copy appsettings.json.config to the directory specified in the … Read more

ASP.NET Core appsettings.json update in code

Basically you can set the values in IConfiguration like this: IConfiguration configuration = … // … configuration[“key”] = “value”; The issue there is that e.g. the JsonConfigurationProvider does not implement the saving of the configuration into the file. As you can see in the source it does not override the Set method of ConfigurationProvider. (see … Read more

What is the difference between app.config file and XYZ.settings file?

UPDATE: In ASP.NET Core Land, configuration is no longer managed via either of these – see this fantastic writeup from Travis Illig with the a-z on Microsoft.Extension.Configuration and Microsoft.Extensions.Configuration.Binder which are effectively a superset of all this Settings (Both from a .settings set and Configuration.AppSettings), are stored in the .config file [alongside lots of other … Read more

Change Azure website app settings from code

You can also use the Azure Fluent Api. using Microsoft.Azure.Management.Fluent; using Microsoft.Azure.Management.ResourceManager.Fluent; using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication; using Microsoft.Azure.Management.ResourceManager.Fluent.Core; … public void UpdateSetting(string key, string value) { string tenantId = “a5fd91ad-….-….-….-…………”; string clientSecret = “8a9mSPas………………………………=”; string clientId = “3030efa6-….-….-….-…………”; string subscriptionId = “a4a5aff6-….-….-….-…………”; var azureCredentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = clientId, ClientSecret = clientSecret }, tenantId, … Read more

Objective-C – Detect when user change the app’s notifications settings

There is no delegate. You need to query the UIApplication property enabledRemoteNotificationTypes periodically, for example in applicationDidBecomeActive:. For details check these answers: Determine on iPhone if user has enabled push notifications View In Lock Screen and enabledRemoteNotificationTypes – iOS5 Edit: If you need to reset the push notification setting and the permission alert, have a … Read more