首先,如果只是直接将access数据库的后缀名改为.asp是无法防止下载的,正确的做法是,建立一个表,为这个表中写入二进制文件,即OLE对象。具体代码如下:
<% Dim DB,RS,SQL DB = "DB.asp" ’这里改成你的数据库,后缀一定要是asp Set Conn = Server.CreateObject("Adodb.Connection") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db) Conn.Execute("Create Table NotDownload(NotDown OLEObject)") Set RS = Server.CreateObject("ADODB.RecordSet") SQL = "Select * FROM NotDownload" RS.Open SQL,Conn,1,3 RS.Addnew RS("NotDown").appendchunk(chrB(Asc("<")) & chrB(Asc("%"))) RS.Update RS.Close Set RS = Nothing Conn.Close Set Conn = Nothing Response.Write "数据库防下载处理完成,请确认您的Access数据库已经改为ASP后缀" %> |
……