Friday, September 24, 2010

Hands was a small component (component entry) _asp


Hands was a small component (component entry)

This article is mainly for the ASP wants to raise the level of their own people to write! The ASP code into components, developers not only accelerates the speed of ASP, but also to protect their code. This article was written out also for users to want to develop components on an introductory course!

Below, we will write a very simple components, with emphasis on know how to develop DLL component, rather than the complexity of code! They have to rely on your own efforts in the future.

Server-side components

First, the server-side components to be different from the client component. Client-side component is transmitted through the network, relying on HTML to work. And can only be useful in IE on. But the server-side component is running on the server side, it perform various operations on the server. Therefore, all browsers can enjoy, it relies on the server rather than the browser.

When IIS is an ASP request execution program, it will first be found in the ASP file, the code between the tags and execute it (can also be between the code). If the ASP program had previously been called, then it will compiled with the memory of the procedure to return HTML code to the user, if not, then it is recompiled. Here ASP CGI a little more than the speed advantage, because the CGI is used for each request is a thread. so far consumed server resources.

Want you to write the program itself will run in IIS!?! Now you on the list! Using VB5 (VB6 of course it is), you can create Dynamic Linked Libraries (DLL files) that can run directly in IIS ( asp file to the request if there are any).

System and software requirements

You need a 32-bit operating system to run ASP. Of course, you have to install IIS or PWS. We the following procedure was windows95 + PWS + VB5 environment development.

Here we go

Start your VB, select the ActiveX icon. This icon can be found in new construction! VB project will provide a default name (project1) and the class name (class1). We will all get rid of these two names. In the renamed before first make sure we have the Microsoft Active Server Pages Object Library, it is very useful in our process. from the menu, select "Project", and then selecting "quote" appears "reference" window, choose Microsoft Active Server Pages Object Library.

To the project and class name

Now we come to based on their hobbies to the project1 and named class1 to it! Name to them is also very important to the future, we will use the project name and class name to create an instance of this component! Later in detail.

How to rename, I do not want to say!
Our project name changed to Exmaple, class name Helloword

How to use project and class

Now we have our own project (Example1) and the class name (HelloWorld). Then we will use them in ASP code names to refer to this component. In ASP so we quote as follows:

Set ObjReference = Server.CreateObject ("ProjectName.ClassName")

A reference for our project is:

Set ObjReference = Server.CreateObject ("Example1.HelloWorld")

Now we will be able to call us with ObjReference created in the component function, subroutine. Now we will write a SayHello subroutine, the code we execute it as follows:

In order to use ASP in Helloword class method, you must write in such a OnStartPage
Functions. As follows:

Public Sub OnStartPage (PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
End Sub

Now, whenever the user to access a file with the components of ASP, IIS will send the ScriptingContext invited us to use our target. This includes all of the ASP ScriptingContext methods and properties. Implementations, which makes our ability to access to 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

Then we will be able to be used in place of VB using ASP in MyApplication Application, empathy can replace the Request, Server ....., but we came here before to OnStartPage to state that these variables:

Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session




[Next]



Objects using ASP

Our variables can now standard ASP objects like to use it!, For example, we often used in the ASP Request.form () to collect data to submit the form. Now we are in our VB to achieve this function, the code is as follows:

With ASP to achieve:

In VB to achieve:

MyTempVariable = MyRequest.Form ("userName")
MyResponse.Write ("you entered" & MyTempVariable & "as your user name")

Instead of using MyResponse Response, we can use all the Response methods, of course, MyResponse name can easily to take, and you may even get Response.
The other thing we have to note that we have established in our class, write OnEndPage Functions, this OnStartPage the opposite! OnStartPage is to create objects, OnEndPage object is destroyed.

Public Sub OnEndPage ()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub

SayHello method

Us to create a sub function that shows "Holle World". This SayHello method is a sub function HelloWorld this class, we later used in the ASP below shows this method

SayHello procedure, very simple!

Public Sub SayHello ()
MyResponse.Write ("Hello World")
End Sub

The preparation of a small component now complete, the remaining work is to compile the component, in the "Project" menu, save it, and take what names can we use Exmaple1.vbp it! Then used in the menu "make exmaple1.dll", to compile into a DLL file. a component of the real done!

Note that compile this component you must first turn off your PWS, and then compile the component. Otherwise VB will tell you that some components in use.

Used in the ASP component of our own.

When you correct the error in the compilation successfully compiled example1 this project, and now you have to come up with your favorite HTML editor to write the following statement, save for the ASP file.

After running you can see the result:

Hello World

Registration Component

If you want your friends and neighbors to share your components, then you'll have in your system, register your component. We generally use Regsvr32.exe to register the component. Registration of your component will appear in the Win95/Win98 the windows / system directory. Here is an example of registration:

Regsvr32.exe C: / wwwroot/Example1/Example1.dll

In your system, VB will automatically register you, so you rarely Regsvr32.exe

We are here just to write a very small component, you can own more written components, but also in a lot of control with VB.
Let us expand our program components to the function it! We hope to see lots of Chinese people component.






Recommended links:



Review Calculators And Converters



Hackers target companies to steal confidential



Win 2000/XP Automatically Restart Solution



DIRECTORY Astrology Or Biorhythms Or Mystic



"Fallout 3" Aircraft Carrier Task Of The City Of Clues And Details Of The Extension



TD commercial trial on April 1 the minimum Consumption of 118 yuan a complete experience



MKV to DivX



SharePoint 2010 Early Glance: Online Editor greatly improved



M2TS to MOV



Gateway Bank of China has become the odds



Using VMware, Vowed To Computer "cloned A Technique"



ASF to MPEG



Compare Benchmarking



Watch COOL mechanical picture production process



No comments:

Post a Comment