我如何prevent直接链接到几个PDF文件吗? [英] How do i prevent direct linking to a few pdf files?

查看:123
本文介绍了我如何prevent直接链接到几个PDF文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站,我需要prevent直接链接到几个PDF文件上。我使用ASP.net 2.0。是否有code一个简单的方法来做到这一点?或者一些简单的IIS设置?

I'm working on a website where I need to prevent the direct linking to a few pdf files. I'm using ASP.net 2.0. Is there an easy way in code to do this? or some simple IIS setting?

现在,我只使用一个标准的定位代码链接到的文件。我可以验证包含锚标记上的页面上的用户,但仍然没有从抓获的URL,将它传递给别人停止用户。

Right now i'm just using a standard anchor tag to link to the files. i can validate the user on the page containing the anchor tag but that still doesn't stop the user from nabbing the url and passing it on to someone else.

推荐答案

我用一个文件提取程序ASP页面和流所需文件的字节,使用正确的内容类型在过去解决了这个头。大致是:

I've solved this in the past by using a file-fetcher asp page and streaming the bytes of the desired file, using the correct content-type in the header. Roughly:


  1. 创建页面fetchfile.aspx

  1. Create page fetchfile.aspx

样品网址:yoursite / fetchfile.aspx N = pdfname.pdf

Sample URL: yoursite/fetchfile.aspx?n=pdfname.pdf

在fetchfile:

In fetchfile:

- Verify user is permitted to access file.
- Check chosen directory for presence of file from query string.
- Set content-type appropriately for file type.
- Open the file and stream all bytes of it to the client.
- Close the file and end the response.


不要在除文件的字节响应发送任何东西。如果发生错误,或者重定向或内容类型设置正确返回错误的HTML。

Do not send anything in the response except the bytes of the file. If an error occurs, either redirect or return error html with the content-type set correctly.

我最后一次这样做,我服了图片,所以我找到了合适的免费的图书馆,写我的错误信息到一个新的自定义图像,然后可能会显示。为了好玩,你可以使用这种技术来提供的内容是意想不到的当有人用热联偷了你的带宽是这样的:

The last time I did this I was serving up images, so I found a suitable free library and wrote my error message into a new custom image that could then display. For fun, you can use this technique to serve up content that is unexpected when anyone steals your bandwidth by hot-linking like this:


  1. 创建不必要的引用名称的黑名单,在数据库表或文本文件。

  1. Create a blacklist with unwanted referrer names, in a database table or text file.

当一个文件请求时,如果用户是不允许的,检查引用在黑名单中,如果没有,让文件中读取。

When a request for a file comes in, if the user is not allowed, check if the referrer is in the blacklist, and if not, let the file be read.

在定期检查提交页面,并决定一个合适的PDF回到惩罚该网站。

On a regular basis, check the referring pages and decide a suitable pdf to return to punish that site.

添加要返回到您的黑名单每个引用的内容,并在引用的黑名单,然后返回备用骗取内容。

Add the content you want to return to your blacklist for each referrer, and when the referrer IS in the blacklist, then return the alternate diddled content.

这是为了让人们真的不可能偷你的东西的好方法。他们的经验是这样的:

This is a great way to make people REALLY unlikely to steal your stuff. Their experience looks like this:


  1. 他们发现,他们希望一些不错的内容借钱。

  1. They find some nice content they want to "borrow."

他们张贴在他们的网站和它的作品就好了。

They post it on their site and it works just fine.

第二天,你看他们的行动,并将其加入黑名单表,但使它所以任何人试图获得内容,而不是得到了某种可爱的小消息:example.com是在偷此内容业主在somecoolsite.com,请让他们知道你是不满他们的行为。

The next day you see their action and add them to the blacklist table but make it so anyone trying to obtain the content instead gets a nice little message of some sort: "example.com is STEALING this content from the owners at somecoolsite.com. Please let them know that you are displeased with their actions."

您有一个良好的笑。

这可能是特别美好的,如果被盗的内容是图像。尴尬嘉豪在等着带宽贼!

This can be especially wonderful if the content being stolen is an image. Embarrassments galore are in store for bandwidth thieves!

一些额外的聪明IP地址和时间比较可能会使得你显示正确的内容,以实际行为人,但错误的内容,他的任何网站访问者......邪恶和美味的。

Some extra clever IP-address and time comparison could possibly make you show the correct content to the actual perpetrator but the wrong content to any of his site visitors... evil and delicious.

这篇关于我如何prevent直接链接到几个PDF文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆