Programming | beginners | If there is a lot of content, please edit it first in this machine so that the session expiration will cause the content to be lost. 20 very useful examples in ASP programming
1. How to use ASP to determine the virtual physical path of your website
Answer: Using 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" >
<%= Server.MapPath ("\")% >
</font ></p >
2. How do I know the browser used by the user?
Answer: Use 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 repeated visits per day
Answer: the solution
<% Startdate=datediff ("D", Now, "01/01/1990")
If strdate< 0 then startdate=startdate*-1
Avgvpd=int ((usercnt)/startdate)% >
Show results
<% Response.Write (AVGVPD)% >
This is It.this 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 get back to the previous page
Answer:< a href= "<%=request.servervariables (" Http_referer ")% >" >preivous page</A >
Or with pictures such as:< img src= "arrowback.gif" alt= "<%=request.servervariables (" Http_referer ")% >" >
6. How to determine the IP address of each other
Answer:<%=request.servervariables ("remote_addr)% >
7. How to link to a picture
Answer:<% @Languages =vbscript% >
<% response.expires=0
Strimagename= "Graphix/errors/erroriamge.gif"
Response.Redirect (Strimagename)
% >
8. Forced Enter Password dialog box
A: Put this sentence on the beginning of the page
<% response.status= "401 not Authorized"
Response.End
% >
9. How to pass variables from one page to another
A: Use the HIDDEN type to pass variables
<% form method= "POST" action= "mynextpage.asp" >
<% for per item in request.form% >
< input namee= "<%=item% >" type= "HIDDEN"
Value= "<%=server. HTMLEncode (Request.Form (item)% > ">
<% next% >
</form >
10. Why I use MsgBox in the ASP program, the program error said no permissions
A: Because the ASP is the server running, if you can display a dialog box on the server, then you have to wait for someone to confirm, your program can continue to execute, and the general server will not be guarded, so Microsoft had to ban this function, and told you in random (:) OH) No permissions. However, ASP and client-side scripting can be combined to display a dialog box, as follows:
<% yourvar= "Test dialog box"% >
<% script language= ' JavaScript ' >
Alert ("<%=yourvar% >")
</script >
11. There is no way to protect their source code, do not give people to see
A: You can download a Microsoft Windows Script Encoder, which can encrypt the ASP scripts and client Javascript/vbscript scripts ... However, after the client is encrypted, only IE5 can execute, server-side script encryption, only the server installed script engine 5 (installed a IE5 have) to perform.
12. How can I transfer query string from one ASP file to another?
A: The former document adds the following sentence: Response.Redirect ("Second.asp?" & Request.ServerVariables ("Query_string"))
13.global.asa files always don't work?
A: Only the web directory is set to Web application, Global.asa is valid, and global.asa the root directory of a Web application is valid. IIS4 can use Internet Service Manager to set application setting how can I make an HTM file Execute script code just like an ASP file?
14. How can I make an HTM file Execute script code like an ASP file?
Answer: Internet sevices Manager-> select Default Web Site-> right mouse button-> Menu Properties-〉 home Directory-> Application settings (Application Setting)-> Click button "Configuration"-> App mapping-> Click button "ADD"-> Executable browse select \winnt\system32\inetsrv\asp. DLL EXTENSION input HTM method exclusions input put.
[1] [2] [3] Next page