Open web.config from console application?

后端 未结 4 1831
萌比男神i
萌比男神i 2020-12-13 05:09

I have a console capplication that runs on the same computer that hosts a bunch of web.config files. I need the console application to open each web.config file and decrypt

4条回答
  •  误落风尘
    2020-12-13 05:38

    Ok I got it... compiled and accessed this so i know it works...

          VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(@"C:\test", true);
                WebConfigurationFileMap wcfm = new WebConfigurationFileMap();
                wcfm.VirtualDirectories.Add("/", vdm);
    
    
                // Get the Web application configuration object.
                Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
    
                ProtectSection(config, @"connectionStrings", "DataProtectionConfigurationProvider");
    

    This is assuming you have a file called web.config in a directory called C:\Test.

    I adjusted @Dillie-O's methods to take a Configuration as a parameter.

    You must also reference System.Web and System.configuration and any dlls containing configuration handlers that are set up in your web.config.

提交回复
热议问题