473,398 Members | 2,165 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,398 software developers and data experts.

Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images directory
with all website images. How can I prevent other websites from creating img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks
Nov 28 '07 #1
7 2328
Unless its a password protected site, you can only really just check your
logs to see if anyone is doing that and block them if they are. I

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Mike" <Mi**@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from creating
img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #2
Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from creating
img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #3
Dave - You mention serving them up on an aspx page. What exactly does that
mean or how would I do that? I understand how to check the
request.urlreferrer, I'm just unfamiliar w/serving an image on an aspx page.

Thanks.

"Dave Bush" wrote:
Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from creating
img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #4
private void Page_Load(object sender, System.EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = image mime type here;
Response.WriteFile(filename);
Response.End();
}

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 10:35 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

Dave - You mention serving them up on an aspx page. What exactly does
that
mean or how would I do that? I understand how to check the
request.urlreferrer, I'm just unfamiliar w/serving an image on an aspx
page.

Thanks.

"Dave Bush" wrote:
Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from creating
img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #5
this adds little protection, as image properties will give the url.
checking the urlreferrer will prevent legitimate users, as many
browser/proxies strip this for security.

you best bet is using a 1 time token on the url.

myimage.aspx?id=<access token>

the accesstoken is a key to the actual image to return. the key should
only be good for 1 use (or limited time use).

again this will only stop casual use, a good hacker could beat this.

-- bruce (sqlwork.com)

Dave Bush wrote:
private void Page_Load(object sender, System.EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = image mime type here;
Response.WriteFile(filename);
Response.End();
}

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 10:35 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

Dave - You mention serving them up on an aspx page. What exactly does
that
mean or how would I do that? I understand how to check the
request.urlreferrer, I'm just unfamiliar w/serving an image on an aspx
page.

Thanks.

"Dave Bush" wrote:
>Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from creating
img
tags with the source as my images? I want to prevent other websites from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #6
Bruce is right. But, you need to decide how important protecting those
images is.

You might be able to get away with checking for a session variable that
the calling page created.

Any method you use COULD be hacked. But, they'd have to have some idea
what you were doing first.

Are the images really THAT important? Could you put a visible water mark
on them instead?

-----Original Message-----
From: bruce barker [mailto:no****@nospam.com]
Posted At: Wednesday, November 28, 2007 11:59 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

this adds little protection, as image properties will give the url.
checking the urlreferrer will prevent legitimate users, as many
browser/proxies strip this for security.

you best bet is using a 1 time token on the url.

myimage.aspx?id=<access token>

the accesstoken is a key to the actual image to return. the key should
only be good for 1 use (or limited time use).

again this will only stop casual use, a good hacker could beat this.

-- bruce (sqlwork.com)

Dave Bush wrote:
private void Page_Load(object sender, System.EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = image mime type here;
Response.WriteFile(filename);
Response.End();
}

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 10:35 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

Dave - You mention serving them up on an aspx page. What exactly does
that
mean or how would I do that? I understand how to check the
request.urlreferrer, I'm just unfamiliar w/serving an image on an aspx
page.

Thanks.

"Dave Bush" wrote:
>Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from
creating
img
tags with the source as my images? I want to prevent other websites
from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks

Nov 28 '07 #7
The images are not THAT important, and I think that one of the methods
recommended here should suffice to accomplish this task.

Right now I think I have a pretty good understanding what you all have
proposed, so I'll get started reviewing them.

Thanks all!

"Dave Bush" wrote:
Bruce is right. But, you need to decide how important protecting those
images is.

You might be able to get away with checking for a session variable that
the calling page created.

Any method you use COULD be hacked. But, they'd have to have some idea
what you were doing first.

Are the images really THAT important? Could you put a visible water mark
on them instead?

-----Original Message-----
From: bruce barker [mailto:no****@nospam.com]
Posted At: Wednesday, November 28, 2007 11:59 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

this adds little protection, as image properties will give the url.
checking the urlreferrer will prevent legitimate users, as many
browser/proxies strip this for security.

you best bet is using a 1 time token on the url.

myimage.aspx?id=<access token>

the accesstoken is a key to the actual image to return. the key should
only be good for 1 use (or limited time use).

again this will only stop casual use, a good hacker could beat this.

-- bruce (sqlwork.com)

Dave Bush wrote:
private void Page_Load(object sender, System.EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = image mime type here;
Response.WriteFile(filename);
Response.End();
}

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 10:35 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Re: Protect an Image File in ASP.NET Web Project?

Dave - You mention serving them up on an aspx page. What exactly does
that
mean or how would I do that? I understand how to check the
request.urlreferrer, I'm just unfamiliar w/serving an image on an aspx
page.

Thanks.

"Dave Bush" wrote:
Place the files in a different directory and serve them up with an aspx
page. Have the aspx page
Check the Request.UrlReferrer prior to serving them up.

You could also use a 404 error handler so that they look like they are
still gifs, but because you are calling them from a directory different
then they are really in, the 404 handler will kick in and serve up the
file for you.
Dave Bush
http://blog.dmbcllc.com

-----Original Message-----
From: Mike [mailto:Mi**@discussions.microsoft.com]
Posted At: Wednesday, November 28, 2007 9:44 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Protect an Image File in ASP.NET Web Project?
Subject: Protect an Image File in ASP.NET Web Project?

Hi. I have an ASP.NET 2.0 web application which contains an Images
directory
with all website images. How can I prevent other websites from
creating
img
tags with the source as my images? I want to prevent other websites
from
serving my image.

For example - How can I prevent another website from doing this?
<img src="http://mywebsitename/images/image1.jpg"

Is this possible? Thanks


Nov 28 '07 #8

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

Similar topics

6
by: fgarciarico | last post by:
I´m developping an application that needs to show some videos, but in a protected envinroment. Any user must be authenticated to see the videos. But for example, if anyone know the path of the...
4
by: David LACASSAGNE | last post by:
Is it possible to set a password to protect the code of an Access VBA project by automation (I already know how to to it manually)? David.
4
by: Steve Peterson | last post by:
Hi I've been beating my head against the wall trying to get this done, with little to no success so I thought I would turn to the .Net community for some help. I have an .NET app in which the...
3
by: SpIcH | last post by:
Hi All, This is all about protecting my data in Executable file. I have developed a program in Visual Basic .NET 2002. I have many questions in mind... please help me to complete my project. ...
7
by: Jean Christophe Avard | last post by:
Hi! I am designing an application wich comes with image file. These images are copyrighted and they have to be accessible only from within the application. At first, I tought I was going to store...
5
by: aiki727 via DotNetMonster.com | last post by:
Hello everyone, Where do I store a bitmap or jpeg that I am using for a forms background image when I deploy the application? Or do I link these files to the app during the deployment? Thanks...
8
by: Bill | last post by:
Anyone have any success in using global.asax to protect images in a folder from being linked to by external websites? I'd tried to use global.asa in the past, with no success. Any help would be...
5
by: Garry Jones | last post by:
I need to create a page with a password where I show photos. How do I stop people from accessing the jpgs directly without going through the password function. I am using Windows XP and have a...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.