Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dealing with a file that does not exist

Status
Not open for further replies.

gpalmer711

IS-IT--Management
May 11, 2001
2,445
GB
Hi All,

I'm developing a site at the moment which in effect will be a simple image hosting site. I will be creating the images using some asp.net code (System.Net.Graphics) and these images will be updated every 30 minutes. This all works fine, however What i now need to do is factor in times when the image does not exist as it is the first time they are using the system. So for example if someone links to <img src=" if imagename.jpg does not exist I want it to be created.

I figured I could just use a custom 404 page and have that redirect to the page that creates the image and then have that redirect to the image. However I just thought I would see if anyone here knows of a better way of doing it.

The site will be hosting on a Windows 2003 server using IIS6.

Many Thanks

Greg Palmer
Freeware Utilities for Windows Administrators.
 
Hi Mark,

Thanks for your prompt reply as always. I don't think I made myself clear enough in the original post.

This site will effectivly be hosting Xbox GamerCards for at least one 3rd party site. So when someone signs up to the 3rd party site they enter their Xbox GamerTag and then there is some code on the 3rd party site that automatically generates the <img src="blah"> link. Of which I have no control over. So if a 3rd party requests an image that does not exist I need to create it on the fly.

Thats why I figured a custom 404 error page would be the best way to go - That would redirect to the aspx page that creates the image - which in turn redirects to the image itself.

Does that make sense or is there a better way of doing it?

Thanks again

Greg Palmer
Freeware Utilities for Windows Administrators.
 
In that case, how about having a page that serves up the image rather than directing the user directly to the image? For example, rather than directing your users to:
Code:
[URL unfurl="true"]http://www.mysite.com/imagename.jpg[/URL]
direct them to:
Code:
[URL unfurl="true"]http://www.mysite.com/mypage.aspx?image=imagename.jpg[/URL]
Then, in "mypage.aspx" find out if the image exists first. If it does, you stream the image to them so that they can see the image as if they had directly browsed to it. If it doesn't exists, you create it and then stream it.

If you don't want to go down this route there are other alternatives that we could use but I'll see what your response is to the above suggestion before we explore them.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Hi Mark,

That actually sounds like the best idea as it also gives me scope to add extra options if needs be.

Thanks for your assistance

Greg Palmer
Freeware Utilities for Windows Administrators.
 
use an ASHX file instead of an ASPX. ASHX is a generic handler for web requests. ASPX is specific to forms, so you have the overhead of html, body, form, input tags.

ASHX has a faster response time because of this (if only a few microseconds).

To access Request/Response and Get/Post use the Context.Request or Context.Response properties.

a quick google search will return plenty of examples []

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top