Archives

Archives / 2007 / December
  • Fetching Connection Strings

    Let's assume you wish to store your database connection string in the <connectionStrings> configuration section of Web.config. This is the best practice in my opinion because you can (and should) encrypt the section in production. Now you have two basic options: Continue reading...

  • Enumerate Application Settings

    Here's my own solution to a problem that seems to plague a lot of .NET developers out there. The problem is how best to enumerate application settings stored in a section of an ASP.NET 2.0 app.config file at runtime. Let's suppose you have a settings file called Color.settings with the following key-value pairs: Continue reading...

  • Custom SiteMapProvider

    Usually custom SiteMap providers are written because we're pulling our nodes from a source other than xml. Jeff Prosise's provider written for SQL Server is a classic example. But I had a case recently in which the out of the box XmlSiteMapProvider was just fine; my problem was that I needed to do some peculiar security trimming on the nodes. No problem, just add roles to the nodes and enable security trimming in Web.config for the provider right? Not exactly. The requirements were that the system had to ship with the ability to turn a major piece of functionality on or off in production. Let's call the functionality "ViewWidgets" and let's say there's an app setting in Web.config called "ViewWidgets" with value="false". That means, the web site should suppress the Widgets unless and until it is flipped to true. Then Widgets should be available to the end user. One way of implementing this would have been to set a generic role or override Web.config in a subfolder. But I wanted the webmaster to be able to flip the flag to true or false in Web.config where he was more comfortable working. The solution turns out to be pretty easy. Just derive a custom provider from XmlSiteMapProvider and override the Initialize method to trim the node based on the app setting: Continue reading...

  • Generics and Nullable Types

    It is often useful in OR mapping to analyze a value type that might be null prior to setting it in a business entity. For instance, SqlDateTime type (in System.Data.SqlTypes namespace) is a value type that is nullable. You can call IsNull to check and Value to retrieve the underlying DateTime type: Continue reading...