Loading custom configuration files

the articles posted by Ricky are very good, but unfortunately they don’t answer your question. To solve your problem you should try this piece of code: ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = @”d:\test\justAConfigFile.config.whateverYouLikeExtension”; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); If need to access a value within the config you can use the index operator: config.AppSettings.Settings[“test”].Value;

Getting value from appsettings.json in .net core

Program and Startup class .NET Core 2.x You don’t need to new IConfiguration in the Startup constructor. Its implementation will be injected by the DI system. // Program.cs public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); } // Startup.cs public class Startup … Read more

How can I add a filter class in Spring Boot?

If you want to setup a third-party filter you can use FilterRegistrationBean. For example, the equivalent of web.xml: <filter> <filter-name>SomeFilter</filter-name> <filter-class>com.somecompany.SomeFilter</filter-class> </filter> <filter-mapping> <filter-name>SomeFilter</filter-name> <url-pattern>/url/*</url-pattern> <init-param> <param-name>paramName</param-name> <param-value>paramValue</param-value> </init-param> </filter-mapping> These will be the two beans in your @Configuration file: @Bean public FilterRegistrationBean someFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(someFilter()); registration.addUrlPatterns(“/url/*”); registration.addInitParameter(“paramName”, “paramValue”); registration.setName(“someFilter”); … Read more

How can you change Network settings (IP Address, DNS, WINS, Host Name) with code in C#

Just made this in a few minutes: using System; using System.Management; namespace WindowsFormsApplication_CS { class NetworkManagement { public void setIP(string ip_address, string subnet_mask) { ManagementClass objMC = new ManagementClass(“Win32_NetworkAdapterConfiguration”); ManagementObjectCollection objMOC = objMC.GetInstances(); foreach (ManagementObject objMO in objMOC) { if ((bool)objMO[“IPEnabled”]) { ManagementBaseObject setIP; ManagementBaseObject newIP = objMO.GetMethodParameters(“EnableStatic”); newIP[“IPAddress”] = new string[] { ip_address }; … Read more

Encrypt Password in Configuration Files? [closed]

A simple way of doing this is to use Password Based Encryption in Java. This allows you to encrypt and decrypt a text by using a password. This basically means initializing a javax.crypto.Cipher with algorithm “AES/CBC/PKCS5Padding” and getting a key from javax.crypto.SecretKeyFactory with the “PBKDF2WithHmacSHA512” algorithm. Here is a code example (updated to replace the … Read more

How to read AppSettings values from a .json file in ASP.NET Core

This has had a few twists and turns. I’ve modified this answer to be up to date with ASP.NET Core 2.0 (as of 26/02/2018). This is mostly taken from the official documentation: To work with settings in your ASP.NET application, it is recommended that you only instantiate a Configuration in your application’s Startup class. Then, … Read more

Using different Web.config in development and production environment

In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration. When creating a web.config, you can expand the file in the solution explorer, and you will see two files: Web.Debug.Config Web.Release.Config They contain transformation code that can be used to Change the … Read more