Wednesday, July 7, 2010

How to API key in web.config C#

web.config.

<

add key="APIKey" value="xxxxx" />

<

add key="username" value="xxxxx" />

<

add key="password" value="xxxxxx" />

 

static void WriteConfig()

{

HttpServerUtility Server = HttpContext.Current.Server;

// Reading a key

String Version = ConfigurationManager.AppSettings["ttttt"];

// Writing a key

ExeConfigurationFileMap FileMap = new ExeConfigurationFileMap();

FileMap.ExeConfigFilename = Server.MapPath(

@"~\Web.config");

Configuration Config = ConfigurationManager.OpenMappedExeConfiguration(FileMap, ConfigurationUserLevel.None);

Config.AppSettings.Settings.Add(

"APIKey", "xxxxxxxxxx");

Config.AppSettings.Settings.Add(

"username", "xxxxxx");

Config.AppSettings.Settings.Add(

"password", "xxxxxxx");

Config.Save(

ConfigurationSaveMode.Modified);

}

No comments: