FAQs about ASP Programming
Q: How can I protect my ASP source code from leakage?
A: Download Microsoft's Windows Script encoder to encrypt ASP scripts, client JavaScript, and VBScript scripts. After the client script is encrypted, only Versions later than ie5 can be executed. After the server script is encrypted, script engine 5 (with ie5 installed) can be interpreted and executed only on the server.
Q: Why does the global. Asa file always fail?
A: The Global. Asa file is valid only when it is placed in the root directory of a site in the Web Publishing directory, but not in a subdirectory of the publishing directory. In addition, you can use Internet Service Manager of IIS4 to set a subdirectory as a site.
Q: Why are ASP files not interpreted for execution?
A: On the IIS server, you do not have the permission to interpret ASP files as scripts. Therefore, ASP files are not interpreted and executed as normal page files by the Web server as script code. We recommend that you create an ASP Directory in the Web Publishing directory, store all ASP files in this directory, and grant the script interpretation permission to the ASP Directory.
Problem: Use response in ASP files. the error "the HTTP headers are already written to the client browser. any HTTP header modifications must be made before writing page content ". How can this problem be solved?
A: This error indicates that the HTTP title is written to the client browser after the page content is written. Any HTTP title must be modified before the page content is written. The solution is to add response. Buffer = true at the beginning of the ASP file and response. Flush at the end of the file.
Q: Why does the session disappear sometimes?
A: A session is like a temporary cookie, but its information is stored on the server (sessionid is saved on the client ). There are several possibilities for the disappearance of session variables. For example, the user's browser does not accept cookies because the session depends on cookies to track users. The session expires after a period of time. The default value is 20 minutes, if you want to change the timeout value of a session, you can set the Microsoft Management Console's web directory → properties → virtual directory → application settings → configuration → app options → Session Timeout option, you can also set it in an ASP script, such as session. timeout = 60. You can set the timeout time to 60 minutes.
Q: How can I know the visitor's information?
A: request. servervariables ("http-User-Agent") obtains the type of the visitor's browser. Request. servervariables ("remote-ADDR") can obtain the IP address of the visitor. The language environment of the visitor can be accessed through the request. servervariables ("http-Accept-language.
Q: How can I transmit a query string from one ASP file to another ASP file?
A: Add the following code to the previous ASP file: Response. Redirect ("second. asp? "& Request. servervariables (" query-string.
Q: How to Control cookies in ASP?
A: To write cookies, use response. Cookies ("coookies name to be written") = data to be written. To read cookies, use: Read data = request. Cookies ("names of cookies to be read ").
Note: The response. Cookies program segment for writing cookies must be placed before the HTML mark and no other HTML code can be found. In addition, cookies must use expires to set the validity period before they can be truly written to the client's hard disk. Otherwise, they are only temporary.
Q: How can I use ASP to send emails?
A: You need to install the SMTP service function of Windows NT Option Pack. The implementation code is as follows:
<%< Br/> set mail = server. createobject ("cdonts. newmail ") <br/> mail. to = "abc@xxx.com" <br/> mail. from = "yourmail@xxx.com" <br/> mail. subject = "topic" <br/> mail. body = "email content" <br/> mail. send <br/> %> 〉 Q: Do I have to set a DSN on the server to connect ASP to the database?
A: Not necessarily, there are two ways to connect ASP to the server database: one is to establish a connection through DSN, and the other is to establish a connection without DSN. To connect to the database through DSN, the system administrator of the server needs to set a DSN in ODBC in the control panel of the server. If the DSN is not set on the server, you only need to know the database file name (such as access, paradox, FoxPro Database) or data source name (such as sqlserver database) to access the database, directly provide the parameters required for the connection.
The connection code is as follows:
Set conn = server. createobject ("ADODB. connection ") <br/> connpath =" DBQ = "& amp; server. mappath ("yourtable. mdb ") <br/> Conn. open "driver = {Microsoft Access Driver (. MDB) }; "& amp; connpath <br/> set rs1_conn.exe cute (" selectfrom authors ") </P> <p> problem: how do I pass variables from one page to another? </P> <p> A: Use the hidden form type to pass variables. </P> <p> <form method = "Post" Action = "mynextpage. ASP "> <br/> <% for each item in request. form %> <br/> <input namee = "<%= item %>" type = "hidden" <br/> value = "too many servers server.html encode (request. form (item) %> "> <br/> <% Next %> <br/> </form> </P> <p> Use session to save variables. </P> <p> <% SESSION ("bh") = request. Form ("bh") %> </P> <p> Use querystring to save the variable. </P> <p> <a herf = "Action. asp? BH = 10 "> query </a> <br/> <% request. querystring (" bh ") %> 〉 Q: How can I use ASP to calculate the number of online users?
A: The number of online users refers to the number of visitors in a period. The length of time is set by the designer.
In this period, the total number of accesses from different IP addresses to the site is the current number of online users. In ASP, the session object is used for statistics. The implementation code is as follows:
Golobal. asa file </P> <p> <script language = "VBScript" runat = "server"> <br/> sub session-onstart <br/> application ("online ") = Application ("online") + 1 <br/> end sub <br/> sub session-onend <br/> application ("online") = Application ("online ") -1 <br/> end sub <br/> sub application-onstard <br/> application ("online ") = 0 <br/> end sub <br/> sub application-onend <br/> application ("online ") = 0 <br/> end sub <br/> </s Online> </P> <p> online. ASP file content </P> <p> <% TMP = Application ("online") <br/> TMP = CSTR (TMP) <br/> dim disp (20) <br/> dim images (20) <br/> dbbits = Len (TMP) <br/> for I = 1 to dbbits <br/> disp (I) = left (right (TMP, I), I-(I-1 )) <br/> next <br/> for I = dbbits to 1 step-1 <br/> images (I) = " "<br/> response. write "document. write ('"& amp; images (I) & AM P; "');" <br/> next %> </P> <p> question: how is the ASP program running time calculated? </P> <p> A: the code used to determine the execution time of ASP programs is as follows: </P> <p> <%< br/> dim T1, t2 <br/> T1 = now () </P> <p> 'detected ASP code </P> <p> T2 = now () <br/> response. write "run this ASP code with" & amp; CSTR (cdbl (t2-t1) * 24*60*60) & amp; "seconds" <br/> %> 〉