久久国产精品亚洲艾草网_黄色视频在线免费观看_国产强伦姧在线观看_无码国产69精品久久久久网站

asp.net數(shù)字報(bào)在防盜鏈方面的技術(shù)

廣告:

程序代碼

<%

’定義函數(shù),用ADODB.Stream讀取二進(jìn)制數(shù)據(jù)

Function ReadBinaryFile(FileName)

Const adTypeBinary = 1

Dim BinaryStream

Set BinaryStream = CreateObject("ADODB.Stream")

BinaryStream.Type = adTypeBinary

BinaryStream.Open

BinaryStream.LoadFromFile FileName

ReadBinaryFile = BinaryStream.Read

End Function

Response.AddHeader "Content-Disposition", "attachment;filename=2.gif"’文件名

Response.ContentType = "image/GIF" ’設(shè)置(1)

response.Binarywrite ReadBinaryFile(server.mappath("2.gif"))’就是你讀取存在本地的文件,防止被

別人知道真實(shí)路徑盜連的。

%>

(1)下面的示例將 ContentType 屬性設(shè)置為其他的常見(jiàn)值。

text/HTML 這個(gè)就不說(shuō)了

image/GIF gif圖片

image/JPEG jpg圖片

application/x-cdf cdf文檔

application/wma 就是西瓜哪個(gè)音樂(lè)類(lèi)型了

具體可以參照 Web 瀏覽器文檔或當(dāng)前的 HTTP 規(guī)格說(shuō)明

這樣再利用asp的儲(chǔ)存session,cookies,以及讀取HTTP頭等特殊功能就可以完全真正的實(shí)現(xiàn)防盜連,這里

沒(méi)有設(shè)置緩存,如果訪(fǎng)問(wèn)量巨大,我想設(shè)置下就會(huì)更好吧。

下面是asp.net

7. 在Web.config中插入下面的配置

<appSettings>

<add key="uploadDirectory" value="uploads" />

</appSettings>

8. 寫(xiě)一個(gè)函數(shù)以下載文件(向客戶(hù)端傳遞文件數(shù)據(jù))

下載文件的代碼

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click

downloadfile("document.pdf") '

End Sub

'This is the function that you have to use

Private Function downloadfile(ByVal strFile As String)

Dim fs As FileStream

Dim strContentType As String

' This is the important part, because you going to use the local path

'to get the file

Dim strPath = Me.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("uploadDirectory")) & "\"

Dim strFileName As String = strFile

fs = File.Open(strPath & strFileName, FileMode.Open)

Dim bytBytes(fs.Length) As Byte

fs.Read(bytBytes, 0, fs.Length)

fs.Close()

Response.AddHeader("Content-disposition","attachment; filename=" & strFileName)

Response.ContentType = "application/octet-stream"

Response.BinaryWrite(bytBytes)

Response.End()

Return True

End Function

廣告:

相關(guān)內(nèi)容

編輯:Admin 時(shí)間:2012/8/24 7:43:16 閱覽:370   返回    
asp.net數(shù)字報(bào)
防盜鏈
掃描關(guān)注53BK報(bào)刊官網(wǎng)
掃描關(guān)注閱速公司微信