Recommended: Introduction to the basics of humanities ASP development What is ASP? ASP is the abbreviation of Active Server Pages, which is the active server page. ASP files have .asp as the extension. What's special about it is that all markup languages that can be used in Html files can be used in ASP files, and ASP files
If we know the actual path of a static file such as: http://www.xx.com/download/51windows.pdf, if the server does not have special restrictions, we can download it effortlessly! When the website provides 51windows.pdf download, how can the downloader not get his actual path! This article will introduce how to use Asp to hide the actual download path of a file.
When managing website files, we can place files with the same extension in the same directory and give a special name, for example, put the pdf file directory as the_pdf_file_s, and save the following code as down.asp. Its online path is http://www.xx.com/down.asp. We can use http://www.xx.com/down.asp?FileName=51windows.pdf to download this file, and the downloader cannot see the actual download path of this file! In down.asp, we can also set whether the downloaded file needs to be logged in and determine whether the downloaded source page is an external website, so as to prevent the file from being stolen.
| The following is the quoted content: Sample code: <% From_url = Cstr(Request.ServerVariables(HTTP_REFERER)) Serv_url = Cstr(Request.ServerVariables(SERVER_NAME)) if mid(From_url,8,len(Serv_url)) <> Serv_url then response.write Illegal link! 'Prevent link theft response.end end if if Request.Cookies(Logined)= then response.redirect /login.asp 'Required to log in! end if Function GetFileName(longname)'/folder1/folder2/file.asp=>file.asp While instr(longname,/) longname = right(longname,len(longname)-1) wend GetFileName = longname End Function Dim Stream Dim Contents Dim FileName Dim TrueFileName Dim FileExt Const adTypeBinary = 1 FileName = Request.QueryString(FileName) if FileName = Then Response.Write Invalid/webpage/asp/041101/24.htm! Response.End End if FileExt = Mid(FileName, InStrRev(FileName, .) 1) Select Case UCase(FileExt) Case ASP, ASA, ASPX, ASAX, MDB Response.Write Illegal operation! Response.End End Select Response.Clear if lcase(right(FileName,3))=gif or lcase(right(FileName,3))=jpg or lcase(right(FileName,3))=png then Response.ContentType = image/* 'The download dialog box does not appear for image files else Response.ContentType = application/ms-download end if Response.AddHeader content-disposition, attachment; 200497141230.htm= & GetFileName(Request.QueryString(FileName)) Set Stream = server.CreateObject(ADODB.Stream) Stream.Type = adTypeBinary Stream.Open if lcase(right(FileName,3))=pdf then 'Set the pdf type file directory TrueFileName = /the_pdf_file_s/&FileName end if if lcase(right(FileName,3))=doc then 'Set the DOC type file directory TrueFileName = /my_D_O_C_file/&FileName end if if lcase(right(FileName,3))=gif or lcase(right(FileName,3))=jpg or lcase(right(FileName,3))=png then TrueFileName = /all_images_/&FileName 'Set the image file directory end if Stream.LoadFromFile Server.MapPath(TrueFileName) While Not Stream.EOS Response.BinaryWrite Stream.Read(1024 * 64) Wend Stream.Close Set Stream = Nothing Response.Flush Response.End %> |
This article is collected and compiled from the Internet. If you are the original author, please write to change the author and source Post#vip.qq.com (change # to @)
Share: Tips: Use GetString to increase the speed of ASP Many ASP programmers have had the experience of executing database queries and then displaying the query results in HTML tables. Usually we do this: The following is the quoted content: