473,395 Members | 1,678 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,395 software developers and data experts.

HTTPHandler question

I'm writing some code to act as a proof of concept which at this point works ok, there is a minor issue I would like to resolve.

What I have is an image database being served in an academic library setting with some pretty tight copyright restrictions. Until now we have simply restricted the images to on-campus use, so you can either VPN/Proxy to the network or use a machine physically on the network to access the image collection.

Before going further, the image collection (folder structure, sizes, etc) is managed through two products we purchased (Extensis Portfolio/Luna Insight). This should explain the obvious as to why I am using a more complicated solution that I probably need.

The goal is to make it so that the website that hosts the images is publicly available but the images require the same campus only use or offer the ability to login to view. If you are not logged in or not on campus, there is a default image that appears instead basically telling you that you need to either login or vpn to have access. The heart of the problem is that not all images have this restriction.

What I've built is an httphandler method that does this. We offer a login method called CAS and if you are not familiar in short you write code that checks to see if a user is authenticated (in your code so either a session or a cookie) and if they are not they are sent to a central website that authenticates them and sends them back to your site. If that explanation isn't enough, just look up CAS authentication and you'll get a bigger picture.

So the program itself displays a page of thumbnail images, clicking the thumbnail takes you to a detail page with a larger image and the metadata for it. On this page there are links to the actual downloadable JPG that comes in multiple sizes.

The httphandler is setup in this manner. If you are not logged in or on campus and the image is restricted, you get the little thumbnail that says you don't have access and to login. If you were to paste the URL into a browser directly to the image (http://...../image1.jpg) you are sent to the login page.

The problem that I am having is that on the detail page I would like to make it so that if you click the link to the image, it acts the same as if you pasted the URL into a window.

Now why this doesn't work now...

What I had to do in the httphandler is to check to see if the image was being called through an <img src=..> tag or if it was just a URL. The only method I could find that would do this for me was the context.Request.UrlReferrer which would tell me if the request ended in .htm or some other web file used in the program that would have an img src tag. If this returned true then it would display the thumnail image. If this was not true then it would force you to login to get the image. However, when you click a link on the image detail page and essentially land on the .jpg image, the value for UrlReferrer will still contain the .htm or whatever extension. So you land on a page that shows the same thumbnail image as before.

I think I can hack around this by making all links directly to images go to a file of a specific extention, and use a url like /getImage.img/2002.jpg since then the request could be further filtered in the handler.

But if I could avoid this sort of "hack" what I ideally would like is for some method to return a value that indicates whether the image is being called by a straight URL or if it is being called from within an <img src =...> tag.

With that said, does anyone have any ideas of either methods or variables I could read this sort of information out of in the context.request?
Dec 21 '07 #1
2 1515
ok, well what I did which I am happy with is this. In the source code the URL to the image looks something like this:
<a href="someimage.jpg"><img src="/images/someimage.jpg?request=html"></a>
Then what I do is check if the referring URL ends in the .html extension or whateve extions I am using, then it looks to see if the rawurl contains "?request=html" and if it does it knows what to do. So now I can display either the proper "error" image or direct them to authenticate depending what they are doing.

I am still open to other methods to consider that I am not using, but since the pages are built dynamically, it is not a big deal to add the query string to each image source call.
Dec 21 '07 #2
Plater
7,872 Expert 4TB
What I was thinking I believe is exactly what you were doing.

In your <img> tag have it something like:
<img src="http://mydomain/mylocation/ImageWanted.jpg?type=PureImage" />

I guess that would mean pasting:
http://mydomain/mylocation/ImageWanted.jpg?type=PureImage
into the URL would ALWAYS give you an image (either your "please login" image or the requested image)

Wheras anything else would either return an image or would redirect to the login page.
So pasting this into the URL:
http://mydomain/mylocation/ImageWanted.jpg

Would either show you the image if logged in, or redirect you to login page.



Don't know if that offers up a better solution then the one you got, was just my idea.
Dec 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Steve | last post by:
let's say that I have a webpage with an <img> tag and it has an invalid src attribute, that is the image it points to doesn't exist. Is there any way to catch stuff like that and handle it? For...
3
by: Jed | last post by:
I have written an HttpHandler which I invoke through an ashx page. The HttpHandler does various things to process the request, then it is supposed to redirect to a confirmation page. Everything...
6
by: David Bowey | last post by:
Hi There! I'm writing a custom HttpHandler to create watermarks on my PNG images of my website. So typically, a PNG image is linked in an ASPX page as follows... <img src="images/test.png"...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
2
by: Alexandre | last post by:
Hi, I have created an HTTPHandler in ASP.NET 2.0 I now the way to add it in the web.config but my question will be stupid... when I compile my application in asp.net 2.0 from vs 2k5... umm...
3
by: Jeeran | last post by:
I need to perform url rewriting to convert this (for example): /blogs/feeds/popular/posts/ to this: /blogs/feeds.aspx?type=popular&type2=posts What I did was the following: 1. Created an...
5
by: zlf | last post by:
Hello, I try to use a custom HttpHandler to add something to session, then display the original page. public void ProcessRequest(HttpContext context) { context.Session = "test"; } But, a...
6
by: David | last post by:
Hi, I'm very new to ASP.NET. I have over 10 years of C++ experience in MFC and Games programming etc, but web programming is something I have just started. Sorry for the rather silly...
5
by: Author | last post by:
I followed the example at http://support.microsoft.com/kb/308001/EN-US/ and created my own HttpHandler. Here is the code: using System.Web; namespace MyNameSpace { public class...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.