Today, for no particular reason, I got attacked by spammers in an unprecedented magnitude. It was not old school e-mail spam – that has been quite stabile the last years on about 100 spam mails per day. No, it was all other kinds of spam.

Comment spam

First of all, my server log has been busy logging 4 times as many comment spam attacks as usual. I normally have about 20 comment spam attacks per day, but today it was almost 80 (and today isn’t over yet). All of them failed to actually post a comment because they tried to make an invalid postback. That is the error message I get from comment spam attacks.

Trackback spam

Normally, I don’t get much trackback spam - maybe a few per day, tops. Today I received 22 which is a record for one day. None of them got through because I check for various conditions about each request and they all failed that check. Strangely enough, there have been no pingback attacks today.

Referrer spam

This is a very annoying way of spamming. I have a referrer log and every time a visitor enters my website with a referrer in the request headers, that request get’s logged so I can see where my visitors come from. Spam bots know this and send requests with fake referrer headers so that I might follow one of those referrer URLs to check it out. It’s pretty obvious most of the time that xxxgallery.com and cheap-mortage.tk is referrer spam. I do have a mechanism to filter them out. It’s very effective, but it also produces some false negatives. I can live with it.

Conclusion

It seems the annual let’s-spam-blogs-day is today and all spammers join forces and fire away. Spammers are people too and it’s nice to see that they can work together and combine various different spam techniques for optimum reach. I’m just glad that all their attempts to pollute my site were futile. Not a single spam attempt got through, just to my logs. It’s actually a good thing because for the first time I got a change to test my spam defences properly. It would have been nice if they would have invited a spammer who could do pingback spam as well. I guess you can’t win them all. Maybe they will invite him for the next annual let’s-spam-blogs-day.

I wonder if this is related to the International Talk Like A Pirate Day which is today. 

Today I had what seemed to be an easy task of serving the rendered HTML of a user control through an Httphandler (.ashx). It’s something I’ve done many times before but never from an HttpHandler. If you want to do it from an .aspx page it is very easy. You just reference the user control and then the code-behind can access it in a strongly typed way when calling LoadControl("control.ascx").

An HttpHandler however does not have a LoadControl method and it doesn’t have a way of referencing user controls like a page does. What started as an easy task now turned into something unknown – reflection was needed.

The code

So, this is the method I came up with using reflection.

[code:c#]

System.Web.UI.Page page = new System.Web.UI.Page(); 
UserControl profile = (UserControl)page.LoadControl("~/controls/profile.ascx");

Type type = profile.GetType();
type.GetProperty("Name").SetValue(profile, "John Smith", null);
type.GetProperty("Age").SetValue(profile, 53, null);

[/code]

Notice that I use a fully qualified relative path to load the profile.ascx control. That is because if you pre-compile the web application it would fail otherwise. I don’t know if it’s a bug or not, but this is the way around it.

I don’t think the solution is very pretty, but it’s not ugly either. It’s short and precise and the reflection part is very transparent. No matter what, it solved the problem of loading user controls from an HttpHandler.