Conflict in Web.Config AppSettings - Secret, ApiKey

Jan 26, 2010 at 2:25 AM

In the facebook.web version 3.0 the hard coded names to web.config file appsettings names are too generic and likely to conflict with other settings.  This was my experience with the 3.0 version.  Secret and Callback were already used by other code in my case.  I needed to be able to use something else.  I jumped in to the source and found it all hard coded!  A couple hours later I have it fixed at least in this regard.

I made a change to the source project to make the appsettings name specific by changing the following:

ApiKey to facebookApiKey
Secret to facebookSecret
Callback to facebookCallback
Suffix to facebookSuffix

The hard coded names are scattered all over the place in the source. I recommend centralizing the hard code in your Constants.cs file in the Facebook project.

I changed the Constants.cs file in the Facebook project by appending a new class to the file IN the Facebook namespace:

/// Defines the constants that point to the appSettings in your web.config file.
public static class PublicConstants
/// Add this to your web.config file appSettings section. 
/// <add key="facebookAPIKey" value="YOURfacebookApiKey"/>
public const string FacebookApiKey = "facebookApiKey";
/// Add this to your web.config file appSettings section. 
/// <add key="facebookSecret" value="YOURfacebookSecret"/>
public const string FacebookSecret = "facebookSecret";
/// Add this to your web.config file appSettings section (this is your application name.)
/// <add key="facebookSuffix" value="YOURfacebookSuffix"/>
public const string FacebookSuffix = "facebookSuffix";
/// Add this to your web.config file appSettings section (this is the page called by facebook.)
/// <add key="facebookCallback" value="YOURfacebookCallback"/>
public const string FacebookCallback = "facebookCallback";

I then modified all the instances where the quoted ApiKey, Secret, Suffix, and Callback occurs for example:

ApplicationKey = WebConfigurationManager.AppSettings["ApiKey"];
ApplicationSecret = WebConfigurationManager.AppSettings["Secret"];


ApplicationKey = WebConfigurationManager.AppSettings[PublicConstants.FacebookApiKey];
ApplicationSecret = WebConfigurationManager.AppSettings[PublicConstants.FacebookSecret];

Likewise I changed all the Suffix and Callback instances as well. The files affected are:
Facebook project -
Facebook.Web project -

At least I only have one place to look for the names now.
In my opinion this project really needs a lot of code clean up and could use a general refactoring.
However it does work - what can you say.