private void SetApplicationSettings() { Configuration configSql = WebConfigurationManager.OpenWebConfiguration("~"); SqlSettingsSection sqlSection = (SqlSettingsSection)configSql.GetSection("SqlSettings"); ApplicationSettings settings = new ApplicationSettings(); settings.SqlDatabaseName = sqlSection.SqlDatabaseName; settings.SqlPassword = sqlSection.SqlPassword; settings.SqlUserName = sqlSection.SqlUserName; settings.SqlServerName = sqlSection.SqlServerName; settings.ConnectionTimeout = sqlSection.ConnectionTimeout; settings.CommandTimeout = sqlSection.CommandTimeout; Configuration configMail = WebConfigurationManager.OpenWebConfiguration("~"); MailSettingsSection mailSection = (MailSettingsSection)configMail.GetSection("MailSettings"); settings.MailFrom = mailSection.AdministrativeMail; settings.MailServer = mailSection.MailServer; SessionManager.SetSessionValue((IndBasePage)this, SessionStrings.APPLICATION_SETTINGS, settings); }
/// <summary> /// save data from textboxes to web.config file /// </summary> /// <returns></returns> private void SaveSettings() { ApplicationSettings settings = (ApplicationSettings)SessionManager.GetSessionValueRedirect((IndBasePage)this.Page, SessionStrings.APPLICATION_SETTINGS); //save in ApplicationSettings object TestSqlConnection(); settings.SqlServerName = txtSqlServerName.Text; settings.SqlDatabaseName = txtSqlDatabaseName.Text; settings.SqlPassword = txtSqlServerPassword.Text; settings.SqlUserName = txtSqlServerUserName.Text; settings.MailServer = txtMailServer.Text; settings.MailFrom = txtAdministrativeMail.Text; Configuration configSql = WebConfigurationManager.OpenWebConfiguration("~"); SqlSettingsSection sqlSection = (SqlSettingsSection)configSql.GetSection("SqlSettings"); sqlSection.SqlDatabaseName = settings.SqlDatabaseName; sqlSection.SqlPassword = settings.SqlPassword; sqlSection.SqlUserName = settings.SqlUserName; sqlSection.SqlServerName = settings.SqlServerName; configSql.Save(); //save in mailsettings congfiguration file Configuration configMail = WebConfigurationManager.OpenWebConfiguration("~"); MailSettingsSection mailSection = (MailSettingsSection)configMail.GetSection("MailSettings"); mailSection.MailServer = settings.MailServer; mailSection.AdministrativeMail = settings.MailFrom; configMail.Save(); SessionManager.SetSessionValue((IndBasePage)this.Page, SessionStrings.APPLICATION_SETTINGS, settings); }