ASP supports only scripted languages though it can still instantiate and utilize COM. While using COM to implement all business logic and data access greatly improves performance, the remaining ASP script is still interpreted rather than compiled, as it is with ASP.NET. This causes a performance hit because interpreted code is much slower than compiled code.
If you're building an enterprise application, your goal should be to place as much of your code as possible into COM components. The only way to place all your code into COM
components is to return a string from your COM layer that represents the HTML you want to display on the client. The only action taken by your ASP page is performing a
"Response.Write" on the returned string. The Response.Write command will actually imbed
the returned string into the HTML. The downside to placing all code in COM components is that, because Visual Interdev is not built to support this type of development, debugging and testing are very difficult.
Here's a quick example of how you might place all your code in compiled COM components while using ASP for "Response.Write".
ASP Page
The following code will reside in the calling ASP page. This page effectively loads up an instance of a class stored in a compiled COM component. The Response.Write command takes the result of the myObject.myFunction method and inserts it into the HTML code that is sent to the client browser.
... ...
<%
Dim myObject
set myObject = Server.CreateObject("myComponent.myClass") Response.Write(myObject.myFunction)
%>
... ...
Function of myComponent.myClass
This is the code placed in the myComponent component. This code effectively builds the HTML string and passes it back to the calling application which in this case is an ASP page. The advantage is the code normally reserved for scripting and interpretation is now compiled into a COM component that will perform better than interpreted code.
... ...
Option Explicit
Public Function myFunction() As String On Error GoTo ErrorHandler
Dim strResult as string
strResult = strResult & "<%@ Language=VBScript %>" strResult = strResult & "<HTML>"
strResult = strResult & "<HEAD><META name='VI60_DefaultClientScript'" strResult = strResult & " Content='VBScript'><META NAME='GENERATOR'" strResult = strResult & " Content='Microsoft Visual Studio 6.0'>" strResult = strResult & "</HEAD>"
strResult = strResult & "<BODY>"
strResult = strResult & "<FORM ACTION='UserLoginProcess.asp' METHOD='post'" strResult = strResult & " id=form1 name=form1>"
strResult = strResult & "<FONT face=Arial><P>"
strResult = strResult & "<TABLE cellSpacing=1 cellPadding=1 width=750" strResult = strResult & " height=425 align=center"
strResult = strResult & " border=1 borderColorDark=#06767d>" strResult = strResult & "<TBODY><TR height=50 ><TD>"
strResult = strResult & "<TABLE cellSpacing=1 cellPadding=1 width='100%'" strResult = strResult & " border=0>"
strResult = strResult & "<TR><TD style='WIDTH: 225px' align=top width=225>" strResult = strResult & "</TD><TD width=100></TD>"
strResult = strResult & "<TD align=top style='WIDTH: 250px' width=250>" strResult = strResult & "<STRONG>User Login</STRONG></TD>"
strResult = strResult & "<TD align=top></TD></TR></TABLE></TD></TR><TR>" strResult = strResult & "<TD vAlign=top align=middle>"
strResult = strResult & "<TABLE cellSpacing=1 cellPadding=1 width='100%'" strResult = strResult & " border=0>"
strResult = strResult & "<TR><TD style='WIDTH: 325px' align=top width=325" strResult = strResult & " height=50>"
strResult = strResult & "<P align=left><A href='../default.asp'>" strResult = strResult & "<FONT size=2></FONT></A> </P></TD>" strResult = strResult & "<TD align=top><P align=left> </P>" strResult = strResult & "</TD><TD align=top></TD></TR><TR>"
strResult = strResult & "<TD align=top><P align=right>User ID:</P>" strResult = strResult & "</TD><TD align=top><INPUT id=text1 "
strResult = strResult & " style='LEFT: 229px; TOP: 153px' name=txtUserId>" strResult = strResult & "</TD><TD align=top></TD></TR>"
strResult = strResult & "<TR><TD align=top height=15></TD><TD align=top>" strResult = strResult & "</TD><TD align=top></TD></TR>"
strResult = strResult & "<TR><TD align=top><P align=right>Password:</P>" strResult = strResult & "</TD><TD align=top><INPUT id=password1"
strResult = strResult & " style='LEFT: 229px; TOP: 191px' type=password" strResult = strResult & " name=password1></TD>"
strResult = strResult & "<TD align=top></TD></TR><TR><TD height=10></TD>" strResult = strResult & "<TD></TD><TD></TD></TR><TR>"
strResult = strResult & "<TD align=top><P align=right> </P></TD>" strResult = strResult & "<TD align=top><INPUT id=submit1 style='LEFT: 229px;"
strResult = strResult & " WIDTH: 107px; TOP: 225px; HEIGHT:"
strResult = strResult & " 24px' type=submit size=33 value='Log in'" strResult = strResult & " name=submit1></TD>"
strResult = strResult & "<TD align=top></TD></TR></TABLE></TD></TR><P></P>" strResult = strResult & "<P></P></FONT></TBODY>"
strResult = strResult & "<P></P><P></P><P></P><P></P><P></P></FORM>" strResult = strResult & "<P></P><P></P><P></P><P></P><P></P><P></P></P> " strResult = strResult & "</BODY>"
strResult = strResult & "</HTML>" myFunction = strResult
Exit Function ErrorHandler: Set oCn = Nothing
App.LogEvent vbObjectError + 1001 & ' ' _
& strErrorDescription, vbLogEventTypeError
Err.Raise vbObjectError + 1001, 'DBConnection.objNewConnection', _ strErrorDescription
Err.Clear End Function
... ...
Placing your presentation code in COM components, as you would with ASP, gives the best possible performance and promotes scalability but is very difficult to implement and support. With ASP.NET you get the performance and scalability advantages of compiled code with none of ASP's disadvantages. ASP.NET completely separates presentation and business logic into different physical files during development; then, once the project is built, the logic files are compiled into a single DLL. When a web page is requested, the DLL sends the
appropriate HTML code to the client. Since ASP.NET was developed with compiled code in mind, Visual Studio .NET can easily debug and test your ASP.NET application.