当前注册人数422815人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB Android   站内搜索 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

Protect files for download

ASP.NET网站防盗链代码

2007年12月11日
VB 7.x, Windows, .NET 1.1, ASP.NET, WebForms, VS.NET2003, Dev
这里的代码是用来保护你的网站上传的文件的,它可以在用户知道完整的文件URL的时候,也无法下载你的文件。这样就可以保护你的资源免于被别的网站盗链的问题。
相关知识

关键之处是,只有用户点击你的网页按钮,才可以执行下面的代码,下载文件。

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
源代码原文下载:
Protect files for download Maybe sometimes you need to protect files for download just is a user is Loged in your web application. But if some user know the full url they can download your files. This article will help you to protect files in a folder inside your web application

源码图片

点击链接查看大图
从本站下载附件及源代码(1个附件,已经成功下载180次)

最值得关注的外文源代码

Openbravo ERP
port scan with asp.net
Building Multi-Tier Web Application in .NET 3.5 Framework Using LINQ to SQL
php4dvd - movie database
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论21次,此处显示最近13次评论! 查看所有评论

goodliness  2017年05月01日
学习 学习
yndxstxy2010jrsx  2015年11月12日
kankana
crystal_716  2015年03月26日
学习了
wys0301mm  2012年02月29日
感谢分享!!感谢分享!!
huliling  2011年11月13日
感谢共享
灵雨飘零  2011年07月02日
感谢分享!!感谢分享!!
hp123456  2008年12月17日
不错的东西
波波  2008年12月17日
收藏了
yan1248  2008年12月12日
收藏了
K+F  2008年10月22日
道你的文件存放的完整路径的时
landy_di  2008年10月22日
很好
author  2008年09月11日
收藏了
leiryhp  2008年08月29日
ASP.NET网站防盗链代码
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明