Several classic ASP applications

Source: Internet
Author: User
Tags mdb database classic asp

1. The following Code demonstrates how to obtain the x and y coordinates of an image from the client browser on the server side. Note that the input control type is image.

<Form>
<Input Name = "ImageMap" Type = "Image" Src = "ImageMap.jpg" Alt = "Click Anywhere">
</Form>

<% ImageMap. x = <% = Request ("ImageMap. x ")
ImageMap. y = <% = Request ("ImageMap. y") %>

2. Use the ADODB. Stream object to download various files on the server in IE browser.

That is, the user is prompted to download the file instead of opening some files in the browser. Note: After the following code is copied to an ASP file, do not add any non-ASP code on the page, such as HTML and Javascript client code.

<%
'--------------------------------------------
Response. Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1

StrFilePath = "file path"
StrFileSize =... file size, optional
StrFileName = "file name"

Response. Clear

'*************************************** * *** 8
'Install MDAC 2.6 or MDAC2.7 on your server
'8 ************************************** * ***** 8
Set objStream = Server. CreateObject ("ADODB. Stream ")
ObjStream. Open
ObjStream. Type = adTypeBinary
ObjStream. LoadFromFile strFilePath

StrFileType = lcase (Right (strFileName, 4) 'file extension

'Determine Content-Types by File Extension
Select Case strFileType
Case ". asf"
ContentType = "video/x-ms-asf"
Case ". avi"
ContentType = "video/avi"
Case ". doc"
ContentType = "application/msword"
Case ". zip"
ContentType = "application/zip"
Case ". xls"
ContentType = "application/vnd. ms-excel"
Case ". gif"
ContentType = ".../../image/gif"

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 = "application/rtf"
Case ". htm", "html"
ContentType = "text/html"
Case ". asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select

Response. AddHeader "Content-Disposition", "attachment; filename = strFileName
Response. AddHeader "Content-Length", strFileSize
Response. Charset = "UTF-8" 'character set UTF-8 for the client browser
Response. ContentType = ContentType

Response. BinaryWrite objStream. Read
Response. Flush

ObjStream. Close
Set objStream = Nothing

%>

3. Improve the response speed of ASP pages

Add the following to the first line of your ASP page:

<% ENABLESESSIONSTATE = False %>

This will close the session object and increase the response rate of your server. A common problem is that an html page contains two framework pages (at least one is an ASP page and the session is used ), this will make it visible only after a framework page (of course this framework page uses session) is loaded.

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

<%
Response. CacheControl = "Public"
%>

This line of code will cache the ASP page on the proxy server, so as to speed up the response speed of the client request dynamic page, some infrequently changed ASP pages will be directly obtained from the proxy server.

4. you need to know that the browser (IE for example) will not parse the carriage return and line feed characters, if you use Response. the write method writes a line containing the carriage return and line break characters to the dynamic page. The result can be imagined. What you need to do is:

<%
Response. Write (Replace (body, vbCrLf, "<br> "))
%>

Use <br> to replace carriage return and line feed. Note: If the carriage return and line feed characters appear in the input/textarea controls of the form, you do not have to do so.

5. Use ASP code to write IIS logs

<%
Response. AppendToLog "the database is being accessed"
%>

After executing 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, the database is being accessed

Note: because the content in the log file is separated by commas (,), do not use commas (,) to write logs.

6. How to access MDB database files on a remote computer

If you connect to the MDB file of a remote computer using ODBC (DSN or other methods), this will generate an error:
Microsoft ole db Provider for ODBC Drivers error '000000'
This file may be accessed by other users or has insufficient permissions.

There are two ways to avoid this error:

Method a. Access by using DAO Engine

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)

Method B. ADO + Jet OLE DB provider

Dim Conn, RS
Set Conn = CreateObject ("ADODB. Connection ")
Conn. Provider = "Microsoft. Jet. OLEDB.4.0"
Conn. Open "\ server \ share \ file. mdb"
Set RS = Conn. Execute (SQL)

Make sure that you have sufficient access permissions to access the MDB file on the remote computer when running the ASP page. before accessing the MDB file, you must first

Log on to the remote computer and add the following code

Set UM = CreateObject ("UserManager. Server ")
UM. LogonUser "Account", "password", "Domain"
...
Open database
...
UM. RevertToSelf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.