473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Disable directlinking to files.

I have a pdf-file, but don't want someone to link to this file from outsite
my own website.

Is it possible to prevent this with ASP?

Thanks, Johan
Nov 18 '05 #1
2 988
You can provide links that point instead to a page that streams the PDF to
the browser using an ID to pick the PDF, so there was no direct access. At
least that way you could restrict access using some criteria you were happy
with.

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

"Tiscali Nieuws" <*******************@hotmail.com**> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
I have a pdf-file, but don't want someone to link to this file from outsite my own website.

Is it possible to prevent this with ASP?

Thanks, Johan

Nov 18 '05 #2
To expand further on John's suggestion, here is some sample code I use to
retrieve an ID from a database, and stream a file which is in a directory
that isn't even accessible via the web...

------ BEGIN CODE ------
Dim fileType As String

Dim fileID As Integer

If Request.QueryString("type") Is Nothing _

Or Request.QueryString("id") Is Nothing Then

ShowNotFound()

End If

fileType = Request.QueryString("type").ToLower

fileID = Integer.Parse(Request.QueryString("id"))

Select Case fileType

Case "a"

'File requested is an attachment.

Dim fileData As DataSet

Dim inputFileName As String

Dim outputFileName As String

Dim fStream As FileStream

Dim reader As BinaryReader

ArticleManager.SetConnection(AppSettings("Database "))

fileData = ArticleManager.GetAttachmentInfo(fileID)

If fileData.Tables(0).Rows.Count = 0 Then ShowNotFound()

inputFileName = fileData.Tables(0).Rows(0)("AttachmentID")

inputFileName = "KBATT" & inputFileName & ".dat"

outputFileName = fileData.Tables(0).Rows(0)("AttachmentName")

If Not File.Exists(inputFileName) Then ShowNotFound()

fStream = New FileStream(inputFileName, FileMode.Open)

reader = New BinaryReader(fStream)

Response.ContentType = fileData.Tables(0).Rows(0)("AttachmentType")

Response.AddHeader("Content-Disposition", "attachment;filename=" &
outputFileName)

Response.AddHeader("Content-Length", fStream.Length)

Response.BinaryWrite(reader.ReadBytes(fStream.Leng th))

reader.Close()

Case Else

ShowNotFound()

End Select

Response.End()

End Sub

Private Sub ShowNotFound()

Dim referer As String

Response.Redirect("Error.aspx?code=404")

End Sub

--------END CODE --------
I was minding my own business when John Timney (Microsoft MVP) blurted out:
You can provide links that point instead to a page that streams the PDF to
the browser using an ID to pick the PDF, so there was no direct access. At least that way you could restrict access using some criteria you were happy with.
"Tiscali Nieuws" <*******************@hotmail.com**> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
I have a pdf-file, but don't want someone to link to this file from outsite my own website.

Is it possible to prevent this with ASP?

Thanks, Johan


--
Insert corny line here
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joe Price | last post by:
Hi all I've formatted one of my xml files for viewing through a web browser using xsl. It works fine in Internet Explorer, however when I use Netscape6 or Opera to view the same page the...
13
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the...
2
by: David Garamond | last post by:
Does it currently work? src/backend/utils/mb/conversion_procs/*/ is not building anything, and 'make install' fails because it tries to copy *.so files. -- dave ...
16
by: MLH | last post by:
If I give someone a runtime app, they can open the database window by pressing the F-11 key. How to prevent???
4
by: venkatbo | last post by:
Hi folks, I'd like to disable the inclusion of tk graphics lib in my py build. Looked around but couldn't find a clear answer. Which one of the following would I need to use in the configure...
4
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output...
19
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement,...
6
by: =?Utf-8?B?TWljaGFlbCAwMw==?= | last post by:
I need to disable the clipboard function in Windows XP. We are having a problem with users using CTRL+C in one program, then using CTRL+V in another. Specifically, they type their password into...
9
by: Laurent ARNAL | last post by:
Hi, I would like to know if there is a way to remove/disable .php handler when the request come from a specific Browser. I ask this because I use dreamweaver / webdav to edit my .php files....
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hi, friends, I am using C#.net 2005 to create a windows application. It has menu items, such as File, etc. Under File, there are more menu items, such as New Files, Working Files, etc. Under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.