If it were me, and there were frequent configuration options I needed to access, I would create/expose some kind of IAppConfiguration which I could drop in to my controllers (using dependency injection). Something like:
public interface IAppConfguration { String MyConnectionString { get; } String ServerPath { get; } } public class AppConfiguration : IAppConfiguration { private readonly HttpContext context; public AppConfiguration(HttpContext context) { this.context = context; } public String MyConnectionString { get { return COnfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; } public String ServerPath { get { return context.Server.MapPath("~/"); } } }
Then you can extend it for different circumstances, sub-sites/areas, etc. Then, bring it in via the controller's constructor:
public class MyController : Controller { private readonly IAppConfiguration config; public MyController() : this(new AppConfiguration(HttpContext.Current)) { } public MyController(IAppConfiguration config) { this.config = config; } // reference config.ServerPath or config.MyConnectionString; }
Taking it a step further, you could add a factory atop this, bring that in as a reference instead, and allow you to get configuration settings for other environments. e.g.
IAppConfiguration config = configFactory.GetConfig(/* environment */);
The thing I like about this approach is allows me to substitute out settings for local [unit/integration] testing. Using base controllers/static classes would make it very difficult to substitute out these values at a later time.