/// <summary>
        /// Override this method to create the custom default provider. Here we allow for different
        /// configuration providers so we don't have to rely on .NET configuration classed (for vNext)
        /// </summary>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            if (string.IsNullOrEmpty(sectionName))
            {
                sectionName = "DbResourceConfiguration";
            }

            IConfigurationProvider provider;

            if (ConfigurationMode == ConfigurationModes.JsonFile)
            {
                provider = new JsonFileConfigurationProvider <DbResourceConfiguration>()
                {
                    JsonConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.json")
                };
            }
            else if (ConfigurationMode == ConfigurationModes.XmlFile)
            {
                provider = new XmlFileConfigurationProvider <DbResourceConfiguration>()
                {
                    XmlConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.xml")
                };
            }
            else
            {
                provider = new ConfigurationFileConfigurationProvider <DbResourceConfiguration>()
                {
                    ConfigurationSection = sectionName
                };
            }

            return(provider);
        }
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            string xmlFile = "XmlConfiguration.xml";
            if (configData != null)
                xmlFile = xmlFile;

            var provider = new XmlFileConfigurationProvider<XmlFileConfiguration>()
            {
                XmlConfigurationFile = xmlFile,
                EncryptionKey = "ultra-seekrit",  // use a generated value here
                PropertiesToEncrypt = "Password,AppConnectionString"
                // UseBinarySerialization = true
            };

            return provider;
        }
Example #3
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            string xmlFile = "XmlConfiguration.xml";

            if (configData != null)
            {
                xmlFile = configData as string;
            }

            var provider = new XmlFileConfigurationProvider <XmlFileConfiguration>()
            {
                XmlConfigurationFile = xmlFile,
                EncryptionKey        = "ultra-seekrit", // use a generated value here
                PropertiesToEncrypt  = "Password,AppConnectionString,License.LicenseKey"
                                                        // UseBinarySerialization = true
            };

            return(provider);
        }
        /// <summary>
        /// Override this method to create the custom default provider. Here we allow for different 
        /// configuration providers so we don't have to rely on .NET configuration classed (for vNext)
        /// </summary>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            if (string.IsNullOrEmpty(sectionName))
                sectionName = "DbResourceConfiguration";

            IConfigurationProvider provider;

            if (ConfigurationMode == ConfigurationModes.JsonFile)
            {
                provider = new JsonFileConfigurationProvider<DbResourceConfiguration>()
                {
                    JsonConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.json")
                };
            }
            else if (ConfigurationMode == ConfigurationModes.XmlFile)
            {
                provider = new XmlFileConfigurationProvider<DbResourceConfiguration>()
                {
                    XmlConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.xml")
                };
            }
            else
            {
                provider = new ConfigurationFileConfigurationProvider<DbResourceConfiguration>()
                {
                    ConfigurationSection = sectionName
                };
            }

            return provider;
        }
Example #5
0
        private void LoadAppConfiguration(SamplesViewModel model)
        {
            // Default Web.Config read with Constructor
            // at first access
            if (model.ConfigTypeSelection == "Default Web.Config")
            {
                // Simply assign the default config object - it gets loaded via
                // the default constructor defined in AppConfig.cs
                this.AppConfig = App.Configuration;

                // force to re-read in case we updated previously
                AppConfig.Read();
            }


            // Explicit object creation for the remaining objects,
            // but you can use the same static constructor approach
            // as with the above

            // Separate Web.Config Section
            else if (model.ConfigTypeSelection == "Different Web.Config Section")
            {
                var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
                {
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };
                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            // Separate Web.AppConfig Section
            else if (model.ConfigTypeSelection == "Different .Config File")
            {
                var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
                {
                    ConfigurationFile    = Server.MapPath("~/WebStore.config"),
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            else if (model.ConfigTypeSelection == "Simple Xml File")
            {
                var provider = new XmlFileConfigurationProvider <ApplicationConfiguration>()
                {
                    XmlConfigurationFile = Server.MapPath("WebStoreConfig.xml"),
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };

                this.AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }
            else if (model.ConfigTypeSelection == "String")
            {
                string XmlString = HttpContext.Application["XmlString"] as string;
                AppConfig = new ApplicationConfiguration();

                if (XmlString != null)
                {
                    // You can always read from an XML Serialization string w/o
                    // any provider setup
                    AppConfig.Read(XmlString);
                }
            }

            // Not implemented since you will need a database
            // this example uses the connection string configured in the Web.Config
            else if (model.ConfigTypeSelection == "Database")
            {
                var provider = new SqlServerConfigurationProvider <ApplicationConfiguration>()
                {
                    ConnectionString = "DevSampleConnectionString",
                    Tablename        = "ConfigData",
                    Key = 1,
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey       = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);

                if (!this.AppConfig.Read())
                {
                    model.ShowError(
                        "Unable to connect to the Database.<hr>" +
                        "This database samle uses the connection string in the configuration settings " +
                        "with a table named 'ConfigData' and a field named 'ConfigData' to hold the " +
                        "configuration settings. If you have a valid connection string you can click " +
                        "on Save Settings to force the table and a single record to be created.<br><br>" +
                        "Note: The table name is parameterized (and you can change it in the default.aspx.cs page), but the field name always defaults to ConfigData.<hr/>" +
                        AppConfig.ErrorMessage);
                }
            }
        }
        private void LoadAppConfiguration(SamplesViewModel model)
        {            
           
            // Default Web.Config read with Constructor
            // at first access
            if (model.ConfigTypeSelection == "Default Web.Config")
            {
                // Simply assign the default config object - it gets loaded via 
                // the default constructor defined in AppConfig.cs
                this.AppConfig = App.Configuration;
                
                // force to re-read in case we updated previously
                AppConfig.Read();
            }
            

            // Explicit object creation for the remaining objects, 
            // but you can use the same static constructor approach
            // as with the above

            // Separate Web.Config Section
            else if (model.ConfigTypeSelection == "Different Web.Config Section")
            {
                var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
                {
                     ConfigurationSection = "WebStoreConfiguration",
                     PropertiesToEncrypt = "ConnectionString,MailServerPassword", 
                     EncryptionKey = STR_SUPERSECRET
                };
                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

                // Separate Web.AppConfig Section
            else if (model.ConfigTypeSelection == "Different .Config File")
            {
                
                var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
                {
                    ConfigurationFile= Server.MapPath("~/WebStore.config"),
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            else if (model.ConfigTypeSelection == "Simple Xml File")
            {
                var provider = new XmlFileConfigurationProvider<ApplicationConfiguration>()
                {
                    XmlConfigurationFile = Server.MapPath("WebStoreConfig.xml"),
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                this.AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }
            else if (model.ConfigTypeSelection == "String")
            {

                string XmlString = HttpContext.Application["XmlString"] as string;
                AppConfig = new ApplicationConfiguration();

                if (XmlString != null)
                {
                    // You can always read from an XML Serialization string w/o
                    // any provider setup
                    AppConfig.Read(XmlString);
                }
            }

            // Not implemented since you will need a database
            // this example uses the connection string configured in the Web.Config
            else if (model.ConfigTypeSelection == "Database")
            {
                var provider = new SqlServerConfigurationProvider<ApplicationConfiguration>()
                {
                    ConnectionString = "DevSampleConnectionString",
                    Tablename = "ConfigData",
                    Key = 1,
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);

                if (!this.AppConfig.Read())
                    model.ShowError(
                      "Unable to connect to the Database.<hr>" +
                      "This database samle uses the connection string in the configuration settings " +
                      "with a table named 'ConfigData' and a field named 'ConfigData' to hold the " +
                      "configuration settings. If you have a valid connection string you can click " +
                      "on Save Settings to force the table and a single record to be created.<br><br>" +
                      "Note: The table name is parameterized (and you can change it in the default.aspx.cs page), but the field name always defaults to ConfigData.<hr/>" +
                      AppConfig.ErrorMessage);
            }
        }