How to write ASP as DLL

Source: Internet
Author: User

How to write ASP as DLL

This article is mainly to the ASP code into components, developers not only speed up the ASP, but also to protect their own code.
Next, we'll write a very simple component that focuses on knowing how to develop a DLL component, not its complex code! It depends on your own future efforts.

Server-side components

First, the server-side components are different from the components of the client. The components of the client are transmitted over the network and depend on the HTML to function. and can only be useful on IE. however, the server-side component is running on the server side, and it performs various operations on the server. So all browsers can enjoy it, It relies on a server instead of a browser.

When IIS is requested to execute an ASP program, it first finds the code between the 〈%%> tags in the ASP file and executes it (or it can be the code between the 〈script runat=server>〈/script>). If the ASP program was previously called, it would return the HTML code to the user using a compiled program in memory, and if not, it would recompile. Here ASP is a bit more speed advantage than CGI, Because CGI is a thread used by every request. This greatly consumes the resources of the server.

Do you want to write a program that can run on IIS itself!?! Now you're all right! With VB5 (of course, now VB6), you can create a dynamic Linked Libraries (DLL file) that can run directly on IIS (if an ASP file is requested).

Requirements for systems and software

You need a 32-bit operating system to run the ASP. Of course you also have to install IIS or PWS. The following programs are developed under the WINDOWS95+PWS+VB5 environment.

Here we go

Start your VB and select the ActiveX icon. This icon can be found in the new project! VB provides a default project name (Project1) and class name (Class1). We'll get rid of all two names. Before renaming, confirm that we have the Microsoft Active Server Pages Object Library, It is very useful in our program. Select project from the menu, and then select References in it, the References window appears
Select the Microsoft Active Server Pages Object Library from.

Naming Projects and classes

Now let's name the Project1 and Class1 according to our hobbies. It's also important to name them, and we'll use the project name and class name to create an instance of this component later in this article.

How to change the name, I do not want to say more!
Our project name is changed to Exmaple and the class name is Helloword

How to use engineering and classes

Now we have our own engineering (EXAMPLE1) and class name (HelloWorld). In the future, we will use their names in ASP code to refer to this component. In ASP we refer to this as follows:

Set objreference = Server.CreateObject ("Projectname.classname")

The reference to our project is:
Set objreference = Server.CreateObject ("Example1.helloworld")
Now we can use objreference to invoke the functions, subroutines that we created in the component. Below we will write a SayHello subroutine, and we execute its code as follows:


〈%
Set objreference = Server.CreateObject ("Example1.helloworld")
Objreference.sayhello
%>


In order to use the ASP method in the Helloword class, you must write a onstartpage in this class
Sub-functions are as follows:


Public Sub OnStartPage (Passedscriptingcontext as ScriptingContext)
Set Myscriptingcontext = Passedscriptingcontext
End Sub


Now, whenever a user accesses an ASP file with this component, IIS transmits the ScriptingContext to our object for us to use. This scriptingcontext includes all the ASP methods and properties. Implementation, This gives us the ability to access all ASP objects. Look at the following code:


Public Sub OnStartPage (Passedscriptingcontext as ScriptingContext)
Set Myscriptingcontext = Passedscriptingcontext
Set MyApplication = myscriptingcontext.application
Set myrequest = myscriptingcontext.request
Set Myresponse = Myscriptingcontext.response
Set MyServer = Myscriptingcontext.server
Set mysession = myscriptingcontext.session
End Sub


In the future we can use MyApplication in VB instead of ASP application, the same can replace the request,server ..., but we came to declare these variables before OnStartPage:


Private Myscriptingcontext as ScriptingContext
Private MyApplication as Application
Private Myrequest as Request
Private Myresponse as Response
Private MyServer as Server
Private MySession as Session


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.