views:

9

answers:

1

Hi all,

I'm pretty noob with ASP.NET programming and i'm a bit confused on a problem that i'm facing right now.

We, as devs in my company, live in a clustered environment like the one shown in figure

alt text

Nothing really special. You see, IIS Websites are duplicated on evry FrontEnd Servers. Business logic resides on BackEnds that are sitting, togheder with DB and NAS File system, behind a firewall.

So communication between the public space and the protected one is permitted only through particular channels, with particular requests, to particular IPs and Protocols.

Now, we were asked to build a site where the user can customize his own environment, upload images that will be dispalyed in his HomePage and other features.

In a classical configuration, a user upload an image that is written in a folder in the site root, and then the HTML refers to that image to populate whatever control to display it. But, when a user connect to our site, the load balancer will choose one particular frontend that's not the same for evry session. So, a user will upload his file, disconnect and then come back only to find that his image is gone, 'couse the Load Balancer has routed his request to a differnt frontend where the image does not exist.

So the need to write a piece of code that pull the file from the NAS behind the Firewall. The upload part is stupid, and i can understand it.

My problem is: when the user connects to his page, how i reference in the HTML an image that's not on the machine the site is running on but on a completely hidden File system?

I thought of writing a WCF that serve the image as as a byte stream, but which ASP.NET control to use on the Page to put the stream content on, and How?

I Know that asking the experts community will bring me the best way to accomplish this.

Hope this is clear enough.

Thanks so much for the replays and excuse me for the bad english form.

+1  A: 

You can write a custom handler (.ashx) that will serve the image as a byte stream. There is a tutorial here

It is possible to set the src attribute of an <img> tag to the custom handler, e.g.

<img src="/data/MyImageHandler.ashx?path=/nasfolder/imagename.jpg" alt=""/>

Depending on the mime-type of the images you are saving / serving (.gif, .jpg, .png) you will need to set the corresponding content-type in the response with

Response.ContentType = "image/jpeg";

You don't have to follow the convention I suggested with the "path" querystring parameter, you just need some way to identify a unique image from a request.

Neil Fenwick