Wednesday, May 5, 2010

How to create ASP application using ASP Object Library

Microsoft ASP Object Library provides five ASP Intrinsic Objects i.e. Request, Response, Server, Session, and Application that can be used in the COM component to develop re-usable code components that can be used in other ASP applications.

Here I am going to show you how you can create ASP application that uses COM component developed in VB that is using ASP object library.

Below are the steps to create very-very simple ASP application.

1. Open the MS Visual Basic 6.0 and create ActiveX DLL project.
2. Rename the project1 as ASPComp and class1 as clsASP.
3. Copy below code in the clsASP class window.

Private oContext As ObjectContext
Private oResponse As Response

Implements ObjectControl

Private Sub ObjectControl_Activate()
Set oContext = GetObjectContext()
Set oResponse = oContext("Response")
End Sub

Private Sub ObjectControl_Deactivate()
Set oContext = Nothing
Set oResponse = Nothing
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = False
End Function

Public Sub HelloWorld()
oResponse.Write "Hello World!
" & vbCrLf
End Sub

4. Now open project-> references window from menu and add reference of following items.
Microsoft Active Server Pages Object Library.
COM+ 1.0 Admin Type Library
COM+ Services Type Library


5. Now go to file menu and make the ASPComp.dll

You are done with creating COM component and now you have to create an ASP page that will comsume this component.

So create a folder named ASPTest in the in wwwroot folder and then create an asp page named MyASP.asp in it.

Open this page in notepad and copy following code in it and save it.

< %
Set oExample = Server.CreateObject("ASPComp.clsASP")
oExample.HelloWorld
% >

Now one last thing to be done is to register the component in the COM+ services. You can do it by setting the class's MTSTransactionMode property = 1 - NoTransaction or through steps given below:

1. Open the Component Services Window and right click on the COM+ Applications
2. From the context menu select new->application
3. A Wizard will open, click on next button.
4. Choose Create Empty application and enter the application name - ASPComp, leave other settings as is and click on next button.
5. Again leave the settings as is and click on next button.
6. Click on Finish button.
7. Now you can see ASPComp in the list of COM+ Applications. Double click on it.
8. Now right click on component and choose new->component
9. A wizard will open, click on the next button.
10. Choose the install new component and browse and select the ASPComp.dll and click on open button.
11. Click on Finish button.
12. Now right click on ASPComp and click on start option.

You are done with the development now time to test it.

Open the IE and type following address in the address bar.

http://localhost/ASPTest/MyASP.asp

You should see - "Hello World" on the page.


Reference: http://www.stardeveloper.com/articles/display.html?article=2000041401&page=1

1 comment:

Sridevi K said...

Regards
Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, SQL, PL/SQL, D2K at training@oracleappstechnical.com | +91 - 9581017828.