Several typical ASP applications

xiaoxiao2021-03-06  114

1. The following code demonstrates how to get the X, Y coordinates of a picture from a client in the client browser, and note that the type of the INPUT control is an Image type.

<% Imagemap.x = <% = request ("imagemap.x") imageMap.y = <% = Request ("ImageMap.Y")%>

2. Use the AdoDb.stream object to download all kinds of files on the server in the IE browser.

That is, please prompt the user to download instead of being opened by the browser. Note that the following code is copied to the ASP file, don't add some non-ASP code in the page:

The code of the HTML and JavaScript clients. <% '------------------------------------------ Response.buffer = Truedim StrfilePath, StrfileSize, StrfileName

Const adtypebinary = 1

StrfilePath = "File Path" StrfileSize = ... file size, optional strfilename = "file name"

Response.clear

'8 ******************************** 8' need you MDAC 2.6 or mdac2.7'8 *********************************************************************************************************************** ***** 8set objstream = server.createObject ("adodb.stream") objstream.openobjstream.type = adtypebinaryObjstream.loadFromFile StrfilePath

StrfileType = LCase (Right (StrfileName, 4)) 'File extension

'Document Decree ".ASF" ContentTyPE = "VIDEO / X-MS-ASF" case "video / x-ms-asf" case "video / x-ms-asf" case "video / x-ms-asf" case "video / x-ms-asf" case "video / avi" copy ".doc" contenttype = "Application / Msword" Case ".zip" contenttype = "Application / ZIP" case ".xls" contentty = "case" .gif "contenttype =" iMAG "CASE" .jpg "," JPEG "ContentType = "image / jpeg" case ".wav" contenttype = "AUDIO / WAV" case ".mp3" contenttype = "Audio / MPEG3" case ".mpg", "mpeg" contenttype = "video / mpeg" case ".rtf "ContentType =" .htm "," html "contenttype =" textType = "textTy / asp" Case Else'Handle All Other FilesContentType = "Application / OcT-stream "end SelectResponse.AddHeader" Content-Disposition "," attachment; filename = strFileNameResponse.AddHeader "Content-Length", strFileSizeResponse.Charset = "UTF-8" 'client browser character set UTF-8Response.ContentType = ContentType

Response.binaryWrite Objstream.readResponse.flush

Objstream.closset objstream = Nothing

%>

3. Enhance the response rate of the ASP page

Add in the first line of your ASP page:

<% EnablesessionState = false%>

This will turn off the session object to enhance your server response rate, and more common problems is that an HTML page contains two frames.

The page (at least one is an ASP page, and uses session), which will make a frame page (of course this box)

After using session in the page, another frame page is displayed after loading.

If you use proxy access, by default, many proxy servers do not dynamically cache the ASP page content, join the following code:

<%

Response.cachecontrol = "public"

%>

This line of code will have an ASP page to have a proxy server, thus speeding up the response rate of the client requests the dynamic page, and some uncommon ASP pages will be taken directly from the proxy server.

4. To know that the browser (IE is an example) will not parse the carriage return and wrap characters. If you write a row with the response.write method, you contain the carriage return and wrap characters to the dynamic page, the result can be imagined What you need to do is:

<%

Response.write (Replace (Body, VBCRLF, "
"))

%>

Use
instead of the carriage return and wrap. Note: If the carriage return and the wrap characters appear in Input / TextArea, etc. in Form,

Don't do this.

5. Write an IIS log with ASP code

<%

Response.AppendTolog "Database is being accessed"

%>

After performing this code, the following string may appear in your IIS log:

127.0.0.1, -, 01/01/00, 12:00:34, W3SVC1, WebServer,

127.0.0.1, 161342, 485, 228, 200, 0, get, /somefile.asp, database is being accessed

Note: Since the content in the log file is separated by comma, the write log content should avoid using a comma.

6. How to access the MDB database file on the remote computer

If you use an ODBC connection (DSN mode or other way) to the MDB file of the remote computer, this will generate an error:

Microsoft OLE DB Provider for ODBC Drivers Error '80004005'

It is roughly that this file may be accessed or there is not enough permission access by other users.

There are two ways below, avoid this error: mode a. Use DAO Engine Access

DIM File, Conn, RS Const Readonly = false file = "//server/share/file.mdb" SET CONN = CreateObject ("DAO.DBENGINE.35"). Workspaces (0) .opendatabase (File,, Readonly) SET RS = conn.openrecordset (SQL)

Way B. ADO JET OLE DB Provider

DIM CONN, RS SET CONN = CreateObject ("AdoDb.Connection") Conn.Provider = "Microsoft.jet.Oledb.4.0" Conn "//server/share/file.mdb" set = conn.execute (SQL )

Determine enough access to access the ASP page to access the MDB file on the remote computer, need to first access the MDB file

Log in to the remote computer, add the following code set um = createObject ("userManager.server") Um.logonuser "Account", "Password", "Domain" ... Open Database ... um.reverttoselff

转载请注明原文地址:https://www.9cbs.com/read-125587.html

New Post(0)