For those interested, the problem was caused by the difference in how HTTP modules (IHttpModule) are handled in IIS and UltiDev Cassini. In our Cassini all modules registered in application's web.config will be called for all requests - not only for ASPX requests like in IIS in its default configuration.
Your IHttpModule code, however, should not assume it always handles only requests for ASPX files. If IIS is configured to send other file types to ASP.NET module, then your IHttpModule implementation will break if it assumes that HttpContext.Current.Handler is always of the System.Web.UI.Page type. While you may get away with such assumption in plain vanilla IIS, fancier configurations of IIS/ASP.NET, or UltiDev Cassini may break your code.
Always check the type of the HttpContext.Current.Handler before casting when you create your own HTTP module.
Best regards,
UltiDev Team.
Please donate at
http://www.ultidev.com/products/Donate.aspx to help us improve our products.