A couple of decisions come to mind. You can use the SessionState class, which maps to the request and receives / sets the information as such (I do this from memory, so this is unlikely to be compiled and intended to transmit a point):
internal class SessionState { string ImageName { get { return HttpContext.Current.Session["ImageName"]; } set { HttpContext.Current.Session["ImageName"] = value; } } }
And then from the controller do something like:
var sessionState = new SessionState(); sessionState.ImageName = "xyz"; var imageName = sessionState.ImageName;
Alternatively, you can create a controller extension method:
public static class SessionControllerExtensions { public static string GetImageName(this IController controller) { return HttpContext.Current.Session["ImageName"]; } public static string SetImageName(this IController controller, string imageName) { HttpContext.Current.Session["ImageName"] = imageName; } }
Then from the controller:
this.SetImageName("xyz"); var imageName = this.GetImageName();
This, of course, is DRY. However, I do not particularly like one of these solutions, because I prefer to store at least the data, if any, in the session. But if you intend to stick to all this information without downloading / distinguishing it from any other source, this is the fastest (most dirty) way I can come up with. I am quite sure that there is a much more elegant solution, but I do not have all the information about what you are trying to do and what the problem is.
Keep in mind that when storing information in a session, you will have to dehydrate / rehydrate the objects using serialization, and you may not get the performance that you think this will do.
Hope this helps.
EDIT: In response to additional information I'm not sure where you want to deploy it, but real-time image processing is a reliable fire that can be hit by a DoS attack. My suggestion for you is this: it assumes that it is public, and anyone can upload an image:
1) Allow user to upload image. This image is placed in the processing queue for background processing by an application or some service. In addition, the name of the image is in the user's personal processing queue — probably a table in the database. You can find background processing information in the web application @ Schedule a job on a hosted web server
2) Process these images and, during processing, display the “processing schedule”. You can get ajax request on the product page, which checks processed images and tries to reload them every X seconds.
3) While the image is being processed, the user can refuse processing, believing that this is the one that uploaded the image. This is available either on the product page displaying the image, or in a separate “user queue” view, which will allow them to remove the image for reasons of sorts.
So, you get some more domain objects, and these objects are queued. I am a strong supporter of the configuration agreement, so the final destination of the product image (s) should be predetermined. Something like:
images / products / {id} .jpg or, if the collection, images / products / {id} / {sequence} .jpg.
You then do not need to know the appointment in the form. This is the same for all images.
Then the queue should know where the temporary image was uploaded and what the product identifier is. The queue worker pushes items out of the queue, processes them, and saves them accordingly.
I know this sounds a bit “structured” than what you originally planned, but I think it is a little cleaner.