Wednesday, March 22, 2006

HTTP Compression in IIS 6.0

The things that nobody told you about HTTP compression:
1. It only works when over HTTP 1.1; however Internet Explorer's default setting is to downgrade your HTTP version to 1.0 if you're accessing the server via a proxy so even though you may think you're compressing the .aspx pages - you are not.
2. Some client programs (i.e. Adobe Reader) don't behave correctly when opening up inline documents (i.e. opening up the document in the browser window) when the content has been transferred as a chunked/compressed stream.
So, when you're testing HTTP compression, use a product like ieHttpHeaders to verify that your results are actually being compressed (you'll see headers like Content-Encoding: gzip, and Transfer-Encoding: chunked), and make sure it works with and without a proxy.

Monday, March 13, 2006

IIS Worker Process Recycling and Prime Numbers

To prevent all your application pools from recycling at the same time ... you should follow the way of the cicada! No I haven't been smoking crack. The theory goes like this: if you have two application pools recycled every M and N hours respectively (where M and N are both prime) then their recycles will only coincide every M x N hours. So, for the default 1740 minutes (29 hours) and the next prime up (31 hours), you're only going to have the problem once every 37ish days!

Friday, March 10, 2006

WindowsPrincipal.IsInRole(...) and cached SID

There is something sinister here that I'm just not getting. There is an ASP.NET 1.1 application under IIS 6.0 with an application pool set to run under the context of a domain user. The application is removed so that we can upgrade it. The domain user is added to a machine local group with additional privileges. A new version of the application is installed and started up. Somewhere in its code the line
WindowsPrincipal.IsInRole(string)
is called (the parameter is the name of the machine local group), but that call fails. The event log shows a success audit for a logon attempt using explicit credentials, but the user's group membership isn't refreshed (even after an iisreset) until the machine is rebooted. If a SID is being cached, it can't be IIS that's doing it, and I'm tempted to believe it's Windows.

Thursday, March 02, 2006

SELECT TOP N

To return only the top N rows in a SQL select statement, it is possible to parameterize the number N in both SQL Server 2000 and SQL Server 2005; you don't have to select the whole result set into a temporary table and whittle down the rows by yourself.
For SQL2K:
SET ROWCOUNT @NumberOfRows
SELECT * FROM SomeTableOfYourChoice
SET ROWCOUNT 0

and for SQL2K5
SELECT TOP(@NumberOfRows) FROM SomeTableOfYourChoice