15 very useful examples in ASP programming
1. How to use ASP to judge your website's virtual physical path?
Answer use mappath method
The Physical Path To this Virtual Website IS:
b> font>
<% = Server.mappath ("/")%>
font> p>
2. How do I know the browser used by the user?
Answer using the Request Object method
Strbrowser = Request.serverVariables ("http_user_agent")
IF INSTR (Strbrowser, "MSIE") <> 0 THEN
Response.Redirect ("FormsieOnly.htm")
Else
Response.Redirect ("FORALL.HTM")
END IF
3. How to calculate the average number of repetitable people per day?
Answer solution
<% startdate = datediff ("d", now, "01/01/1990")
IF strdate <0 Then StartDate = startdate * -1
Avgvpd = int ((usercnt) / startdate)%>
Show results
<% response.write (avgvpd)%>
That is it.this page has been viewed sincennound 10,1998
4 How to display a random image?
<% DIM P, PPIC, DPIC
PPIC = 12
Randomize
P = int (PPIC * RND) 1)
DPIC = "Graphix / Randompics /" & P & ". GIF"
%>
display
5. How to return to the previous page?
Answer preivous page
Or with images such as: >>>>>>
6. How to determine the other party's IP address
Answer younger = Request.serverVariables ("remote_addr)%>
7. How to link to a pair of pictures?
<% @ Languages = VBScript%>
<% response.expires = 0
StrimageName = "graphix / errors / errooriamge.gif"
Response.Redirect (StrimageName)
%>
8. Forced input password dialog box?
Answer this sentence to put the beginning of the page
<% response.status = "401 not authorized" response.end
%>
9 How to transfer variables from one page to another?
Answer with hidden type to transfer variables
<% form method = "post" action = "mynextpage.asp">
<% for each item in request.form%>
Value = "<% = Server.htmlencode (Request.form (item))%>>>>>
<% next%>
form>
10 Why do I use MsgBox in the ASP program, the program is wrong, no permissions?
Answer Since the ASP is the server running, if you can display a dialog in the server, then you have to wait until the determined, your program will continue to execute, and the general server will not be deserved, so Microsoft has to ban this function. And let you tell you (:) Oh) no permissions. But ASP and client script combination can display a dialog, as Follows:
<% Yourvar = "Test Dialog"%>
<% script language = 'javaScript'>
Alert ("<% = Yourvar%>")
script>
11 Is there a way to protect your source code, don't give it to people?
Answer You can download a Microsoft Windows Script Encoder, which can encrypt the ASP script and client JavaScript / VBScript script. . . However, after the client encryption, only IE5 can execute, after the server-side script is encrypted, only Script Engine 5 installed on the server can be executed.
12 How can I transfer Query String from an ASP file to another?
Answer the predecessor file Add the following sentence: response.redirect ("second.asp?" & Request.servervariables ("query_string"))
13 global.asa files always don't work?
Only the web directory is set to Web Application, Global.asa is only valid, and Global.asa is valid in the root directivity of a Web Application. IIS4 can use Internet Service Manager to set Application Setting how to make the HTM file like an ASP file can execute script code?
14 How can I make the script code like an ASP file?
Answer INTERNET SEVICES Manager -> Select Default Web Site -> Right Mark -> Menu Properties -> Home -> Application Setting -> Click the button "Configuration" -> App Mapping -> Click the button "Add" -> EXECUTABLE BROWSE Selection /Winnt/System32/inetsrv/asp.dll Extension Enter HTM Method Exclusions Enter PUT.DELETE All OK, but it is worth noting that the HTM should also be processed by ASP.DLL, efficiency will reduce 15 how to register Component?
There are two ways to answer.
The first method: Hand-register DLL This method is used from IIS 3.0 to IIS 4.0 and other web server. It requires you to execute in the command line mode, enter the directory containing DLL, and enter:: // regsvr32 Component_name.dll, for example, C: / Temp / Regsvr32 aspemail.dll which registers the specific information of the DLL into the registry in the server. This component can then be used on the server, but this method has a defect. When the component is registered with this method, the component must have the corresponding setting NT anonymous account with permission to execute this DLL. In particular, some components need to read the registry, so the method of this registration component is only used in the case where there is no MTS on the server. Use: regsvr32 / u aspobject.dll Example C: / Temp / Regsvr32 / u Aneiodbc.dll
The second method: Using the MTS (Microsoft Transaction Server) MTS is an added feature of IIS 4, but it provides huge improvements. MTS allows you to specify that only privileged users can access components and greatly improve the security settings on the website server. The steps to register the components on the MTS are as follows: i) Open the IIS Management Console. II) Expand Transaction Server, right-click "PKGS Installed" and select "New Package" III) Click "CREATE AEMPTY PACKAGE" iv) to name the package V) Specify the Administrator account or use "Interactive" (if the server is often Is the use of administrator login) VI) Now uses the right-click on the "Components" that you just created under the package. Select "New Then Component" VI) Select "Install new component" [b] vii) Find your .dll file and select Next to complete. To delete this object, just select its icon, then select Delete. Note: Special pay attention to the second method, it is used to debug the best way to write the components you write, without having to restart the machine each time.