CSharpFeeds - All your C# feeds in one place.

Sponsors

Wednesday, September 13, 2006

Remotely Access to Configuration Files in ASP.NET 2.0

by Keyvan Nayyeri via Keyvan Nayyeri on 9/13/2006 6:55:19 AM

It helped me a lot today.  I knew it's useful but now I'm sure it's twice useful!!

ASP.NET 2.0 comes with a cool new feature that lets you to deal with configuration files on fly via APIs.  You can read a configuration file then modify it through your codes.

Alright, this isn't something new for a real .NET 2.0 developer but I have to point it again!  You can read configuration files from remote server.  System.Web.Configuration.ConfigurationManager.OpenWebConfiguration() method has six overloads that let you to read configuration files locally or remotely then assign them to a Configuration object to modify them.

What will follow is an instance that reads a Community Server configuration file from a server, writes its connectionstring and adds a new AppSettings item then saves the changes.

protected void Page_Load(object sender, EventArgs e)

{      

    Configuration configuration = WebConfigurationManager.

        OpenWebConfiguration("/CS2160804900", "Default Web Site",

        null, "KEYVANNAYYERI");          

 

    // See what's there

    Response.Write(configuration.AppSettings.Settings

        ["SiteSqlServer"].Value);

 

    // Add something new

    configuration.AppSettings.Settings.Add("Keyvan", "Nayyeri");

 

    // Save changes

    configuration.Save();

}

If I open this configuration file, can see the changes:

<appSettings>

  <add key="SiteSqlServer"

      value="server=(local);uid=;pwd=;Trusted_Connection=yes;database=CS2160804900" />

  <add key="SiteSqlServerOwner"

      value="dbo" />

  <add key="MachineValidationKey"

      value="B387B75D996FF473FC21EC10605CA49E520E9B11" />

  <add key="MachineDecryptionKey"

      value="B3C730067B56DD5381F5BF473E83E3038181459C0F33CEE6" />

  <add key="MachineValidationMode"

      value="SHA1" />

  <add key="ComponentArt.Web.UI.ClientScriptLocation"

      value="~/Utility/componentart_webui_client" />

  <add key="Telligent.Web.UI.ClientScriptPath"

      value="~/Utility/telligent_web_ui" />

  <add key="Keyvan"

      value="Nayyeri" />

</appSettings>

Now playing: Dj Aligator - Club Mix

email it!bookmark it!digg it!

Original Post: Remotely Access to Configuration Files in ASP.NET 2.0

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us