Friday, May 23, 2008

New Weezer Album

As many of you may know, Weezer is my favorite band. In eleven days (June 3 2008) they are releasing their next album, "Weezer". It will their third self titled album, this time nicknamed "The Red Album".

The video for their single, "Pork and Beans", came out on YouTube today! If you keep up on the internet's viral videos, you'll find it pretty funny.

Below is a list of videos I compiled that are included (in order of first appearance):

Is it sad or impressive I recognized 80% of them? Please tell me if you know any that I've missed. :-)

Thursday, May 15, 2008

Finicky Configuration.RegexStringValidator

I was working on a custom ConfigurationElement for an HttpModule and I needed two properties. They both needed to be in the form of a URL (but only the host) and one was required. Regular expressions are a great tool for easily verifying a string is in a certain format and Microsoft was nice enough to include the RegexStringValidatorAttribute. So I tried this:

[ConfigurationProperty("Url", IsRequired = true)]

[ConfigurationProperty("Url2", IsRequired = false)]

If you know regular expressions you can see a simple URL like "" should validate. Neither one worked, plus it gave me the misleading error that "" wasn't validating.

After a bit of fiddling around, I figured out that at some point the RegexStringValidator is validating the default value. In this case it's an empty string which is not valid. This makes sense for Url2 if it's not provided but it told me "" was invalid.

The second one was an easy fix. Since it's not required, I changed the regular expression to allow "" and now it works.

[ConfigurationProperty("Url2", IsRequired = false)]

I can't do the same for the first one because I don't want an empty string to be valid. It's required so it's never empty but I guess when it initializes it loads the default value. Adding a DefaultValue that is valid does the trick.

[ConfigurationProperty("Url", IsRequired = true, DefaultValue = "http://localhost")]

You don't have to worry about the DefaultValue much because if you do not include the property at all you'll get the error, "Required attribute 'Url' not found." and if you include an invalid Url, you'll get the error, "The value does not conform to the validation regex string '^https?://[A-Za-z\d\-_\.]+$'."