Saturday, December 27, 2008

Web 2.0 Design: How To

I ran across this great article on web 2.0 design.

This guy has a lot of good suggestions for the emerging web designer, and he backs up all his key points with examples and reasons. I'd recommend reading this through completely before beginning your next design.

Monday, December 8, 2008

Elmah Error Logging and Secure SMTP

[EDIT: As of 1.0, Elmah natively supports ssl with the useSsl property making the below tweaks unneccessary.]

For those of you who don't know elmah, check it out. Elmah is s a great, open source tool for logging all the errors on your web application.

One enhancement I have made to the source is adding secure smtp capability. This is important for those of us who like to use Google hosted email, which only rides on secure protocols.

The changes are quite simple. The only class you need to modify is the ErrorMailModule. There are three steps to modifying the source:

1. Add a property (I've called mine SmtpSecure).
2. Load the property from the config in OnInit.
3. Enable ssl on the SmtpClient in the SendMail function.

public class ErrorMailModule : HttpModuleBase, IExceptionFiltering
// Add the SmtpSecure property

private bool _smtpSecure;
protected virtual bool SmtpSecure
get { return _smtpSecure; }

protected override void OnInit(HttpApplication application)
// initialize the property
// this should be done in two steps for error trapping reasons

bool smtpSecure = Convert.ToBoolean(GetSetting(config, "smtpSecure", bool.FalseString));

// ... after the error handlers are attached

_smtpSecure = smtpSecure;


// Enable ssl on the smtp client in SendMail
protected virtual void SendMail(MailMessage mail)
// ... after client is instantiated

if (SmtpSecure)
client.EnableSsl = true;


That's it! The last thing to do is add the attribute in your web.config:

subject="Unhandled Exception"
smtpSecure="true" />

Monday, October 13, 2008

IIS 7.0, FTP 7, and Firewalls

I've spent a lot of time over the past few weeks setting up IIS 7.0 on new servers.  One step in that setup was the creation and authentication of several FTP sites.  In this post I have compiled a number of troubleshooting tips gathered from around the webosphere.  Hopefully you will find them useful.


The IIS team has put together a new FTP service which they are calling FTP 7 (available here). This service offers IIS 7 management console integration, which was lacking in the RTM of Windows Server 2008, as well as new user isolation features.  There are some tricky aspects of this new FTP service which may get you stumped the first time you setup an FTP site.

As far as User Isolation goes, you can do nothing better than thuroughly aquaint yourself with this article.  Let me simply add what may appear obvious, but is no less irritating: you must uninstall the IIS FTP role service shipped with Server 2008.

On to firewalls:

Standard (unsecured) FTP uses port 21 as a control channel.  This brings me to symptom number 1:

- Symptom: FTP connection times out waiting server:
- Solution: Open up port 21 on your server firewall.  You can do this through the firewall manager in Server 2008 or by entering at the command prompt:
netsh advfirewall firewall add rule name="FTP (no SSL)"  
action=allow protocol=TCP dir=in localport=21
However, not all FTP modes operate the same.  In passive mode FTP 7 dynamically selects an available port over which to transfer data to the client after the connection is established on port 21.  And so symptom number 2:

- Symptom: Failed to retrieve directory listing
- Solution: Check user permissions, if permissions are in order enable stateful ftp connections.
netsh advfirewall set global StatefulFtp enable
This allows the firewall to open specific ports (controlled by the OS) when the FTP service needs to create a passive connection.

Naturally there are other possible problems.  I simply failed to recall them as off this posting, or did not encounter them in my own cases.

Thanks to Jaro Dunajsky for the stateful tip.  You can read his entire article, which also covers secured FTP, here

Friday, August 22, 2008

Welcome to MethodicMadness

My name is Joel Potter. I'm a software developer for Data Research Group. My field of work is ASP.NET in C#, but I have fiddled around with numerous other languages. My purpose in creating this blog is to share with the community at large all the little tricks and quirks I find in C# and .NET.

I hope to keep the contents of this blog educational and helpful. Therefore I am always willing to hear a second opinion. If you find anything to add or correct in my posts, please let me know either by comments or by email.