20 very useful examples in ASP programming

xiaoxiao2021-03-06  56

1. How to use ASP to judge your website's virtual physical path: Using mappath method

the physical path to this Virtual Website IS : <% = server.mappath ("/")%> 2 How do I know the browser used by the user? A: a method using the Request object 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 repetitions per day Answer: Solution <% StartDate = Datediff ("D", NOW, "01/01/1990") if strdate <0 dam stdate = startdate * -1 avgvpd = int 4 Usercnt) / startdate)%> Display result <% response.write (avgvpd)%> That Is it.this page has been viewed Since November 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"%> Show

5. How to return to the previous page answer: "> preivous page or with images: <% = Request.ServerVariables (">>

6. How to determine the other party's IP address answer: <% = Request.serverVariables ("remote_addr)%>

7. How to link to a pair of pictures: <% @ languages ​​= VBS cript%> <% response.expires = 0 strimagename = "graphix / errors / errooriamge.gif" response.redirect (strimagename)%>

8. Forced input password dialog box: Put this sentence to the beginning of the page <% response.status = "401 Not Authorized" response.end%> 9. How to transfer variables from one page to another: Hidden Type to transmit variable <% form method = "post" action = "mynextpage.asp"> <% for each item in request.form%>