473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTPHandler question

11 New Member
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 1540
wickedHangover
11 New Member
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?r equest=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=h tml" 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 Recognized Expert Expert
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
997
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 example, if I detect a missing image, I could instead return a NoImageAvail.jpg image instead? Weird question and I'm not sure how to ask it, but I suspect it could be something that could be handled somehow. Thanks. Steve
3
7976
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 up to the redirect works fine, but I can't get the redirect to work. If I do a ... context.Response.Write("Hello World"); .... the HttpHandler works great and the browser loads the text fine, but if I change it to ...
6
5592
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" alt="testing" /> So I created an HttpHanlder to handle PNG images, have mapped the PNG extension in the IIS and also added the HttpModule section in the web.config file.
7
2925
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="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031" validate="True"/> </httpHandlers>
2
1311
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 what is the name of the assembly that is produced? I cannot seem to find it anywhere on my server, I ve tryed to publish, compile and still
3
6310
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 http handler that parses the url and based on it will execute another aspx page using Server.Execute
5
4331
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 empty page is rendered with this HttpHandler, should I add some
6
235
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 question, but can someone explain what a HTTPHandler is for? I gather they can handle custom file extensions, but they seem to be
5
7315
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 SyncHttpHandler: IHttpHandler
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.