0

Ich versuche, eine Web.config-Datei im Advanced Installer .MSI-Assistenten mit den Benutzerverbindungszeichenfolge-Eingabedaten zu erstellen.Speichern in web.config, fügt eine zusätzliche "config" -Erweiterung hinzu

Warum ergibt dies eine Datei web.config.config mit einem zusätzlichen config und wie vermeide ich es?

Ich denke, meine Open oder Save ist nicht richtig?

Es ist eine benutzerdefinierte Aktion, innerhalb einer .MSI, lief ich von Advanced Installer, aber es sollte keine Auswirkungen haben, denke ich.

[CustomAction] 
public static ActionResult EncryptConnStr(Session session) 
{ 
    try 
    { 
     var path = Path.Combine(@"C:\Users\radbyx\Documents", "web.config"); 
     var connStr = BuildConnStr("foo", "foo", "foo", "foo"); 

     Configuration config = ConfigurationManager.OpenExeConfiguration(path); 
     ConnectionStringsSection section = (ConnectionStringsSection)config.GetSection("connectionStrings"); 
     section.ConnectionStrings.Add(new ConnectionStringSettings(GetConnectionStringName(), connStr)); 

     // Encrypt 
     //section.SectionInformation.ProtectSection(ConnStrEncryptionKey); 

     // Save the configuration file. 
     config.Save(ConfigurationSaveMode.Modified, true); 

     return ActionResult.Success; 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message + "Trace: " + ex.StackTrace, ex.Message); 
     throw; 
    } 
} 

Antwort

2

Dieses Verhalten wird von ConfigurationManager.OpenExeConfiguration verursacht erwarten Sie den Pfad zu einer ausführbaren Datei zur Verfügung zu stellen, nicht eine Konfigurationsdatei.

Um eine Konfigurationsdatei explizit zu öffnen, um die Überlastung verwenden, die eine Karte nimmt:

var map = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath }; 
configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); 
+0

Wow es funktioniert, du bist der Mann. Sollte schon vor langer Zeit gefragt haben. Wieder einmal ist SO die beste Seite da draußen :) – radbyx

+1

Gern geschehen. Freue mich zu helfen :) –

Verwandte Themen