Tuesday, September 25, 2007

Migrating to IIS 7

Just received my new laptop last week. I decided to go ahead and install Vista Ultimate 64-bit (I have 4 GB of RAM - the 32 bit version only sees 3).

Overall, considering how many rants I've read about Vista, I have to say I'm quite pleased. My machine is pretty speedy, apps are pretty snappy. The only headache was to get our web app to run on IIS 7 (64-bit).

Here are a few things to keep in mind:

- After installing IIS, it looks like you're ready to go. .Net is integrated, all versions of the framework are already installed (except 3.5 of course). Your web.config files are recognized. But for some reason, you won't be able to run any ASP.NET pages. That's because by default, IIS installs the bare minimum. You'll need to go back to the "Turn Windows features on and off" admin console and install ASP.NET support.

- Win 32 compatibility: we're not yet going to switch to x64 platform on production. Thus we're going to keep compiling for Win32. This caused more problems as IIS runs 64-bit apps by default. You'll need to check the "Enable 32-Bit Applications" option on your application pool.

- ISAPI filters: we're using Helicon's ISAPI_Rewrite for URL rewriting. Yes, I know we could now get rid of it and write a .Net HttpModule to deal with this, but we're not quite ready to move to IIS 7 on production. So to get this to work, I had to install a few more add-ons in IIS. More here. Because we're using 32-bit compatibility mode, we installed the 32-bit version.

- VS debugging: make sure you install the "Windows Authentication" IIS module for debugging to work in Visual Studio. Also, set the "manage pipeline mode" to "Classic".

- User impersonation: the default IIS users are now "Network Service" (just like Wind Server 2003) and "IIS_IUSRS".

- Configuration Settings: certain sections (such as HTTPHandlers and HTTPModules) are now locked by default. You'll need to change that setting in "c:\windows\system32\inetsrv\config\applicationHost.config" and set the "overrideModeDefault" attribute to "Allow" on the sections you want to allow.

- I had to remove all the default assemblies (System, System.Web etc...) from my Web.Config compilation section for the site to work as those were duplicates of the assemblies specified in the master web.config file. Not sure yet how this will impact the site once released on IIS6.

I might have forgotten a couple of things, but at least this should put you on the right track.

Tag Clouds - didn't think the web 2.0 mullet could be so omplex

Yes, we have our own tag cloud. I'm not a big fan of those, but I guess some users like them.
The secret of tag clouds relies in normalizing your tag sizes. I found out that there's a bunch of different approaches to the problem, with various results. We started from the following control:

http://www.codeproject.com/useritems/cloud.asp

Works fine, but I didn't like the way the normalization was being done. It assumed 7 steps in its normalization process, and relied on 7 css styles to render each step. Too hard-coded for my taste.

Instead we used the following algorithm when normalizing values:

private static int NormalizeWeight(double minValue, double maxValue, double weight, double maxWeight)
{
double retVal;
double m;
if (minValue > maxValue)
{
m = (minValue - maxValue) / Math.Log(maxWeight);
retVal = minValue - Math.Floor(Math.Log(weight) * m);
}
else
{
m = (maxValue - minValue) / Math.Log(maxWeight);
retVal = Math.Floor(Math.Log(weight) * m + minValue);
}
return (int)Math.Abs(retVal);
}

This allows to normalize font size, color (by passing rgb values) - you name it. The result looks pretty good actually. Just make sure your max weight is greater than 1 or it's not going to work. So before calling the method, check your tags. If every single tag in the cloud has only one match, set the number to your the minimum value and skip the normalizing method.

Control of the day

We are implementing a Flash Banner rotator on our web site. To render the flash movie we've been using the following web control:

http://www.flash-control.net/

Very happy with it. Some feature I've found valuable:

- IE security alert workaround is built in.
- Plug-in detection, redirection etc... built in.
- Ability to access Flash Vars as a collection in your code-behind.

Well worth the $15!

Visual Studio 2005 web site publishing nightmare (2)

We've been using Visual Studio Team Suite for over 6 months now, and I have to say - it solved most of my problems. Yes, it's very pricey. But for our small team releasing very often, the man hours it's saved us so far paid for the heavy licensing costs.

Database Schema Synchronization

VS for Database Developers is my new friend. The Schema Compare tool saves me at least 4 hours per release, and a ton of stress gets removed from my shoulders. Just do a schema compare between your dev database and production, and 90% of the time - unless your new schema requires data deletion, which shouldn't happen very often - it works perfectly. I just move our database from production to staging, run the schema compare tool, save the SQL script, run it on staging. Then we run our tests, and if everything is successful, we just run the script on production when releasing. After 6 months and 6 successful releases, I haven't found any problems with it other than the weird UI bug that randomly hides connection strings. The data comparison tool can be pretty handy, too.

Unit Testing

MS did a great job duplicating all the nice features of NUnit. For NUnit users, migrating to VS Team System unit testing means virtually to learning curve. And the following tool makes it easy to port your old unit tests over to Visual Studio:

http://jamesnewkirk.typepad.com/posts/nunit_converter_v11.html

Overall VS Unit Testing in itself doesn't for a whole lot more than NUnit other than provide a tight integration with Visual Studio. The real benefit is when you start using your unit tests for load testing, and use the code coverage report to see what sections of your code are not covered.
Web Testing

I'm happy with VS' web testing. The recorder is fine to get started, but the true power of the web testing tools is its parametrization features, scripting and database integration. In a couple hours we developed a data-drive test that virtually tested every single one of our 3500+ web pages. Use Fiddler to record AJAX requests, and you're set - I don't have yet a good javascript test harness, but other than that our web testing is looking pretty good.

Load Testing

Just pick which unit or web tests go in your scenario, a few parameters and you're set. Very easy. In terms of performance counters, I'm still experiencing some weird behaviors. For instance, from my XP machine, when trying to access certain IIS or ASP.NET perf counters from my Win Server 2003 testing server (like req/sec), all I'm not getting anything back. I need to rely on the client machine's counters, or I need to open a remote desktop connection to the server and view the counters that way. I've tried contacting MS about this on various forums, but I don't have an answer yet.

There's still a ton of features I haven't tried yet, like code analysis. I ran it once, and got hundreds of messages back. Most of them seem to deal with coding best practices (casing etc...), but a few were dealing with performance. I guess we'll need to look at this in details at some point.

There's also the whole Team Foundation Server side of things that we haven't played with yet. So far we've been happy with SVN, but it looks like Team Foundation Server offers some nice features in terms of build management etc...

More later!