SoFunction
Updated on 2025-04-14

ASP essence source code collection (five-year summary) page 3/20


Examples of useful asp programming (I)
1. How to use Asp to determine the virtual physical path of your website
Answer: Use the Mappath method
< p align="center" >< font size="4" face="Arial" >< b >
The Physical path to this virtual website is:
< /b >< /font >
< font color="#FF0000" size="6" face="Arial" >
< %= ("\")% >
< /font >< /p >
2. How do I know the browser the user is using?
Answer: Use the Request object method
strBrowser=("HTTP_USER_AGENT")
If Instr(strBrowser,"MSIE") < > 0 Then
("")
Else
("")
End If
3. How to calculate the average number of repeated visits per day
Answer: Solution
< % startdate=DateDiff("d",Now,"01/01/1990")
if strdate< 0 then startdate=startdate*-1
avgvpd=Int((usercnt)/startdate) % >
Show results
< % (avgvpd) % >
that is page have been viewed since November 10,1998
4. How to display random images
< % dim p,ppic,dpic
ppic=12
randomize
p=Int((ppic*rnd)+1)
dpic="graphix/randompics/"&p&".gif"
% >
show
< img src="../../< %=dpic% >" >
5. How to return to previous page
Answer: < a href=../../"< %=("Http_REFERER")% >" >preivous page< /a >
Or use an image such as: <img src="../../" alt="< %=("HTTP_REFERER")% >" >
6. How to determine the other party’s IP address
Answer: < %=("REMOTE_ADDR)% >
7. How to link to a picture
Answer: < % @Languages=vbs script % >
< % =0
strimagename="graphix/errors/"
(strimagename)
% >
8. Force password input dialog box
Answer: Put this sentence at the beginning of the page
< % ="401 not Authorized"

% >
9. How to pass variables from one page to another
Answer: Use the HIDDEN type to pass variables
< % form method="post" action="" >
< % for each item in % >
< input namee="< %=item% >" type="HIDDEN"
value="< %=((item)) % >" >
< % next % >
< /form >
10. Why do I use msgbox in asp program? The program error says there is no permission
Answer: Since asp is run by the server, if a dialog box can be displayed on the server, you have to wait until someone presses OK before your program can continue to be executed. Generally, there will be no one on the server, so Microsoft has to ban this function and tell you randomly (:) Haha) that there is no permission. However, ASP and client scripts can display a dialog box, as follows:
< % yourVar="test dialog"% >
< % s cript language='javas cript' >
alert("< %=yourvar% >")
< /s cript >
11. Is there a way to protect your source code and not let people see it
A: You can download a Microsoft Windows s Script Encoder, which can encrypt the asp script and client Javas Script/vbs Script script. . . However, after the client is encrypted, only ie5 can be executed. After the server is encrypted, only s Script engine 5 is installed on the server (installing one ie5 can be found).
12. How can I transfer query string from one asp file to another?
Answer: The former file adds the next sentence: ("?" & ("QUERY_STRING"))
Files always don't work?
Answer: Only when the web directory is set to web application can it be valid, and it can be valid in the root directory of a web application. IIS4 can use Internet Service Manager to set application settings How can the htm file execute script code like an asp file?
14. How can the htm file be able to execute script code like an asp file?
Answer: Internet Services Manager -> Select default web site -> Right mouse button -> Menu properties -> Home directory -> Application Settings -> Click the button "Configuration" -> App mapping -> Click the button "Add" -> executable browser Select \WINNT\SYSTEM32\INETSRV\ EXTENSION Input htm method excclusions Enter all OK. However, it is worth noting that this way, the HTM will also be processed, and the efficiency will be reduced.
15. How to register components
Answer: There are two ways.
The first method: Manually register DLL This method is used from IIs 3.0 to IIs 4.0 and other Web Servers. It requires you to execute it in the command line, enter the directory containing the DLL, and enter: regsvr32 component_name.dll For example, c:\temp\regsvr32 It will register the specific information of the dll into the registry in the server. Then this component can be used on the server, but this method has a flaw. After registering a component using this method, the component must have the corresponding anonymous account set to NT and have permission to execute this dll. In particular, some components need to read the registry, so the method of registering components is only used to unregister this dll when there is no MTS on the server. To unregister this dll, use: regsvr32 /u example c:\temp\regsvr32 /u
The second method: Using MTS (Microsoft Transaction Server) MTS is a new feature of IIS 4, but it provides a huge improvement. MTS allows you to specify that only privileged users can access components, greatly improving security settings on the website server. The steps to register a component on MTS are as follows:
1) Open the IIS Management Console.
2) Expand transaction server, right-click "pkgs installed" and select "new package".
3) Click "create an empty package".
4) Name the package.
5) Specify the administrator account or use "interactive" (if the server often logs in with administrator).
6) Now use right-click the expanded "components" below the package you just created. Select "new then component".
7) Select "install new component" .
8) Find your .dll file and select next to finish.
To delete this object, just select its icon and select delete.
Note: Pay special attention to the second method, which is the best way to debug the components you write yourself without having to restart the machine every time.
Previous page1234567891011121314151617181920Next pageRead the full text