Http Client Protocol Issues

If you use any of these solutions, Please let me know so I can track if any of this is useful to you! Thanks! This is an area to share observations I have made working with Http Client Protocols and the associated technologies. I currently work for the Microsoft team that supports the WinInet, WinHTTP and System.Net API's and classes associated with these technologies. This is not a replacement for Microsoft Support, but an area to discuss these technologies. These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified at Microsoft - Information on Terms of Use

Writing an ISAPI Filter with .NET (Managed Code) will result in poor performance of you ASP.NET web applications

David Wang wrote an excellent post about this in 2006:  http://blogs.msdn.com/david.wang/archive/2006/02/09/Can-I-write-an-ISAPI-Filter-using-Managed-Code.aspx

This includes writing ISAPI code that even USES managed components.  Anything that needs to load the CLR will result in poor performance of the ISAPI and worse, result in ASP.NET not functioning correctly.

ASP.NET loads the CLR when it initializes.  During this loading it does many things to configure the CLR.  One example is that it creates on GC thread for each processor on the system.  It also sets up some defaults for the thread pools.  When you write your ISAPI in managed code or include a COM Visible .NET component through COM in your code, your ISAPI loads the CLR.  Since only one CLR can be loaded per process, ASP.NET will not create and configure the CLR and you are left with a severely crippled system.

This problem can also occur if you write an ISAPI Extension.  Your Extension could load the CLR runtime if you hit a static file first, initialize the CLR in the ISAPI Extension by using .NET or a COM Visible .NET object and then hit your ASP.NET application after this initialization.

You can clearly see this in a multi processor machine if you create a filter that uses a Managed code COM component.  Without your filter in place, hit an aspx page on the site and use DebugDiag to take a dump of the w3wp.exe process.  Then analyze this dump with DebugDiag.  You will see a GC thread initialized for each processor core installed on your server.  On my server I have a quad proc CPU and I see 4 threads with this in the call stack: mscorwks!SVR::gc_heap::gc_thread_function.

Then I created a simple ISAPI filter from one of the existing Platform SDK samples and simply instantiated a COM Visible .NET component.  I installed the ISAPI filter and re-ran my test.  As expected, I saw only 1 thread with mscorwks!SVR::gc_heap::gc_thread_function.

This problem manifests itself not only with the GC threads but all the information set by the processModel (see http://msdn.microsoft.com/en-us/library/7w2sway1.aspx).  In theory you could come up with some sort of scheme to read the machine.config file and parse and set this information, but this is untested and definitely not supported (read: you are on your own).

If you really are in need of writing Managed Code, you should investigate the Managed Pipeline in IIS 7 and use that http://msdn.microsoft.com/en-us/library/ms227673.aspx.  There are a couple of other workarounds you could explore like out of proc components etc... but these would all create performance issues for a Filter or Extension.

Please let me know if this blog post was useful to you!

 

Published Monday, August 03, 2009 9:12 AM by jpsanders
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Shawn Liang said:

Thanks all. It saves me a lot of time trying this.

I saw people trying to figure why his isapi extension cannot call a managed module on other forum. They really have to read this article.

November 2, 2009 8:45 PM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker