Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.45 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What is the best place to configure a MongoDB connection in ASP.NET MVC?
  2. <appSettings>
  3.     <add key="MONGOHQ_URL" value="mongodb://localhost/YourDBName"/>
  4.  </appSettings>
  5.        
  6. public class ConfigEnvironment
  7.    {
  8.       public static string GetConnectionString()
  9.       {
  10.          return ConfigurationManager.AppSettings.Get("MONGOHQ_URL") ??
  11.                 "mongodb://localhost";
  12.       }
  13.    }
  14.        
  15. MongoDatabase.Create(ConfigEnvironment.GetConnectionString())