Capitalizing the First Letter in All Keys of a JSON Object using C#

It took me some time to get this right, drawing from discussions on StackOverflow, but here is code that will capitalize the first letter of every key in a JSON object.

public static JObject Capitalize(JObject obj)
{
  JObject newObj = new JObject();
  foreach (var o in obj)
    {
      string key = o.Key;
      string newKey = char.ToUpper(key[0]) + key.Substring(1);
      JToken value = o.Value;
      if (value.HasValues)
      {
        try
        {
          JObject child = JObject.Parse(value.ToString());
          JObject newValue = Capitalize(child);
          value = newValue;
        }
        catch (Exception)
        {
        }
      }
      newObj[newKey] = value;
    }
  return newObj;
}

FTP Does Not Mix with VPN

Just posting this in case you run into this problem.  A couple of weeks ago, I was helping a customer troubleshoot her FTP connection to the hosting company that I work for.  After going through the standard troubleshooting checklist of performing trace route and telnet tests, shutting down antivirus and firewall hardware/software, and restarting the computer, I couldn’t figure out why it was connecting and then immediately terminating the connection.  When I tried it on my end, it worked fine.  It turns out the customer had an active VPN connection running, so once she turned it off, everything worked again.  So next time you’re having trouble, try turning off your VPN.

Implementing a 410 Status Code Using C#

Here’s how you can setup a 410 Status Code using C#.  Just place this code in the code-behind file in the Page_Load event handler, replacing www.domain_name.com with your domain name, of course:

Response.StatusCode = 410;
if (Request.ServerVariables["SERVER_NAME"].ToString().ToLower() == "www.domain_name.com");
Response.Write("410 Gone");