Friday, 3 April 2009

Converting classic ASP page to ASP.NET aspx page

If you have already developed some asp page , cut & paste that server code in page(not on designer) but in html view. In page directive add this code.

<%@ Page AspCompat ="true" %>

<%@ ASPCOMPAT="true" %> directive, is for STA Single threaded apartment pool.

We use such syntax , reason is we use use com components in classic asp that are not developed in .Net and ASP.NET use multithreaded apartment (MTA) by default

Late Binding

as always, asp might contain adodb library and connection to database. C# is strongly typed language , we can not simply use ADODB in it.

so we need reflection namespace for binding.

<%@ Import Namespace="System.Reflection" %>

for instance if you ve created
connection object,
its methods(Open) and recordset's execute will be invoked thought late binding.
conn.GetType().InvokeMember("Open",BindiingFlags.InvokeMethod,...)(see MSDN for full parameters details).

It is always a better idea to use early binding for performance reason therfore one can use TLBimp.exe tool to convert old Com components into .Net assemblies.

No comments:

Post a Comment