Scott Cate Weblog 

scott.cate@myKB.com
http://scottcate.myKB.com



Scott Cate KB > ASP.NET Code Samples - Findings > ASP.NET Class Start Over
Search the Knowledge Base
 
Start Search in the Following Category
Date Modified
Sunday, August 01, 2004
Web.Config + string.format() Trick

One of the most common questions about the web.config file is... Is it secure?

Well it's as secure as you make it. Anyone with access to the file system, probably has access to the web.config file. So here's a little obfuscation trick. Move some of your sensitive data out of the web.config, or pull it form different parts of the web.config with string.format().

Consider the following web.config entry.

<add key="DBConnection" value="Data Source={0};User Id={1}; Password={2};Initial Catalog={3};"/>

So this is a SUPER generic connection string, and now in my application on start I can pull data from another, more secure area, like the DPAPI.

string server = "localhost";
string user = "user";
string password = "password";
string catalog = "catalog";
string ConfigDBString = Appsettings DBConnection

string connection = string.format(ConfigDBString, server, user, password, catalog);

Then you have your connection string. Obviously these values are not hard coded as in the example above, but I'm sure you get the point.

UPDATED: August 1, 2004
After reading this, my buddy DonXML sent me a note about his Object Oriented approch to this topic. Here are his comments...

I saw your post on the connection string stuff in the web.config file, and was wondering if you saw my Encrypted Connection String code example at GotDotNet.  You could either use it instead of your example, or, just use the base ConnectionString class as a simple and easy way to parse your connection string into it’s components (in an OO style).  I also have a SqlServerConnectionString class and an OracleConnectionString Class that inherit from the base class, with all the rules from the respective documentation implemented (so you can’t build a connection string that will not work).

Very helpful indeed, thanks Don.


All rights reserved. All details are the personal opinion of Scott Cate.
All trademarks referenced are the property of their respective owners.
Scott Cate is a lead programmer for www.myKB.com and
owner of The Arizona .NET User Group and an all around nice guy ;)


Knowledge Base Software - myKB.com

 

Cameron Cate Pictures
Cameron Cate Pix

Site Navigation

Home
Knowledge Base
Wiki Discussions
Photo Album

Sites I Own & Run


Easy Search ASP.NET
mykb.com knowledge base software logo
myKB.com
Knowledgebase Software

KBAlertz.com
Arizona .NET user Group
Group Leader

Affiliations


ASP.NET MVP
2004
2005
2006
2007
2008
2009


Blog Sites I Read

Brady Gaster
Rob Howard
G. Andrew  Duthie
Robert McLaws
Alex Lowe

World of Scott.Net

Scott Guthrie
  -  Father of ASP.NET

Scott Watermasyk
  - .Text (Weblog)

Scott Sargent
Scott Mitchell
ScottG.net
Scott Bellware
Scott Forsyth
Scott Hanselman
Scott Cate

Favorite Books


ASP.NET Cookbook


First Looks @ ASP.NET 2.0