COM InteroperabilityThe common language runtime enables .NET objects to interoperate seamlessly with traditional COM components. ASP.NET exposes the familiar Server.CreateObject(ProgId) API to developers for creating late-bound references to COM.
Dim myConn
myConn = Server.CreateObject("ADODB.Connection");
Like ASP, you can also create traditional COM components using the ASP.NET also continues to support the existing ASP intrinsic interfaces ObjectContext Intrinsic Flow, OnStartPage, and OnEndPage. Supporting these interfaces means that you can use existing components (Commerce Server, Exchange, and so on) in ASP.NET pages. These interfaces are not enabled by default but are explicitly turned on using the following page directive: <%@ Page ASPCompat="true" %> This directive causes ASP.NET to create unmanaged ASP intrinsic objects and pass them to COM components used in the page. It also runs the page in an STA thread pool. See the following section for information. Performance ConsiderationsIn ASP.NET, the thread pool is a multithreaded apartment (MTA) by default, which can affect the performance of traditional apartment-threaded Visual Basic 5 and Visual Basic 6 components. TheASPCompat="true" attribute enables an STA thread pool to address performance with existing Visual Basic components on a per-page basis.
Calling between managed and unmanaged components also incurs a marshaling cost, which can impede the performance of your pages. Every scenario yields different performance characteristics, so it is important to test adequately before deciding whether interoperability is the right choice for your application. However, in nearly all scenarios, rewriting your COM components in managed code provides performance benefits. See the ASP.NET Performance section for more information and important tips. Section Summary
|