Encrypting and Decrypting Config Files
Thursday, November 19, 2009, 05:38 AM - Programming, .NET, C#, VB.NET, ASPX
I've talked for years about how you need to encrypt and decrypt Web.config and App.config files, but it took a spur for me to actually look it up. Here is the command for those of you as lazy as me:

c:windowsMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pef connectionStrings . -prov DataProtectionConfigurationProvider


Decrypting is just as easy:

c:windowsMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pdf connectionStrings .

Just a note, this only works on Web.config files. If you want to encrypt an App.config, just rename it Web.config, run the tool, then change the name back.

If you want to get hardcore and write your own tool, it's all available in the API:

Aaron Feng's Blog


Configuration configuration = ConfigurationManager.OpenExeConfiguration(appConfig);
ConfigurationSection section = this.configuration.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
configuration.Save(ConfigurationSaveMode.Modified);
}


To decrypt just do the oposite:

if (section.SectionInformation.IsProtected)
{
// …
section.SectionInformation.UnprotectSection();
// …
}


[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |   ( 2.9 / 657 )
Forcing HTTPS
Wednesday, April 22, 2009, 12:49 PM - Programming, .NET, C#, ASPX
I was wondering recently how to force the pages of my websites to always go to SSL, and found this little beauty. Stick it in your base page a viola, you are good to go. Oh yeah, want to debug on your local machine, just set requireSSL to false in your forms authentication block (just don't forget to set it back for production!)


protected void Page_Load(object sender, EventArgs e)
{
if (FormsAuthentication.RequireSSL == true){
if (HttpContext.Current.Request.IsSecureConnection == false){
Response.Redirect(Request.Url.ToString().Replace("http:","https:"));
}
}
}


[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |   ( 2.9 / 75 )
NHibernate Links
Friday, October 19, 2007, 10:37 AM - C#, NHibernate
Since I do so much work with NHibernate I thought it might be of interest to start maintaining a list of links related to this topic, so here they are, in no particular order:

Benjamin Day's blog on NHibernate

My NHibernate Data Layer Generation Project at Sourceforge

[ 2 comments ] ( 35 views )   |  [ 0 trackbacks ]   |  permalink  |   ( 3.1 / 293 )
Cruise Control
Tuesday, June 19, 2007, 09:36 AM - .NET, C#, NUnit
I have been playing with Team Foundation Server from Microsoft, and took the opportunity to do some research on the similar technologies for non-MS platforms. CruiseControl.net is a continuous integration product, and this article provides a nice introduction. Another nice article gives a nice ramp-up description.

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |   ( 3 / 298 )
Cassini Web Server
Tuesday, June 19, 2007, 09:16 AM - .NET, C#
I found this the other day while researching a way to deploy my c# web apps to a client machine. It's the cassini web server from UltiDev, compiled as a web service, with built-in web management and configuration.

[ add comment ]   |  [ 0 trackbacks ]   |  permalink  |   ( 2.9 / 289 )

Back Next