Presumably, your intranet is set up so that your public-facing web server can "see" the server on which the photos reside, but the photo server itself is not public-facing. The web site contains links to the photos on the photo server, but since that server is not public-facing the photos do not show up (except when run on localhost, which can see the photo server).
This code snippet shows the basics of one way to do this in .NET:
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "image/jpeg";
using (Bitmap bmp =
(Bitmap)Bitmap.FromFile(
@"\\internal-photoserver\shared drive\bobsmith.jpg"))
{
bmp.Save(
HttpContext.Current.Response.OutputStream,
ImageFormat.Jpeg);
}
HttpContext.Current.Response.End();
}
// needs these two using statements:
using System.Drawing;
using System.Drawing.Imaging;
Basically, instead of rendering the page with a link to the image file, the server instead reads the file and streams it to the client along with the rest of the page (so the browser never needs to access the photo server). As long as the web server can see "internal-photoserver", this code will work and display the photo in the calling client's browser, even when that client is not able to access "internal-photoserver".
The above code sample will display the photo, but that will be the entire page. I'm rusty with ASP.NET, but I'm sure there's a simple way for this code to instead render the image to a placeholder, so you can display other stuff around the photo.
Disclaimer: I do have to add this bit of advice from MSDN:
Caution
Classes within the System.Drawing
namespace are not supported for use
within a Windows or ASP.NET service.
Attempting to use these classes from
within one of these application types
may produce unexpected problems, such
as diminished service performance and
run-time exceptions.
Sound advice (although what they're saying here is that instead of making the graphics classes either super-fast but unsafe or super-safe but slow, they instead chose unsafe and slow), and it might be possible to do this with plain-ol' System.IO
instead, although I'm guessing that wouldn't work with all platforms (because of endianness and whatnot).
Update: Yep, this is a lot easier and safer:
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "image/jpeg";
byte[] bytes = File.ReadAllBytes(
@"\\internal-photoserver\shared drive\bobsmith.jpg");
HttpContext.Current.Response.OutputStream.Write(bytes, 0, bytes.Length);
HttpContext.Current.Response.End();
}
// need this using statement:
using System.IO;
This method would be better for heavy server usage, but you'd need to make sure the images were already in a browser-friendly format (not BMP). Plus, I'm think this would fail when serving up the images to platforms with a different byte ordering than your server, but I don't know.
The first method would be useful if the images were in a non-browser-ready format, or if you need to process them in some way before displaying (like shrinking them and making all their info look like a driver's license or something - I think programmers like me are the reason MSDN recommends not using System.Drawing in ASP.NET).
Finally: Well, I realized that the only reason the first two methods were showing an image in the browser was because the code was changing the content type to image and then sending an image's bytes, so you couldn't use this to display an image as part of an HTML page (i.e. with other text and stuff around it).
The only thing I could come up with was to have one page that just used the above method to write out an image to the response stream, and then another page with an IFRAME on it with its src
set to the image page.
IFRAMEs are bad, or else they aren't. You could instead use a variant of this code and save the JPEG out to a temporary location on the public-facing server, and then build the login page so that it includes a link to this temporary file. You'd have to secure this file and clean it up eventually, of course.
There might be a much smoother, built-in way for ASP.NET to handle this problem, but you never know. I'm trying to get back up to speed with ASP.NET again after a relatively idle period, so it was more fun to chase this approach down.