This tutorial shows how to display a random image upon page load, and then keep that image until the session expires. A new random image will be chosen on new sessions, and remain. C# version.

This tutorial will show how we can choose a random image to display on page load, and this same image will remain for the duration of the session. This means that no matter how many times the visitor refreshes the page, the image will remain the same. However, if the browser is closed and the session ends, a new image will be chosen at random upon a new session start, and remain until the session ends, again.
First, we need to use System.IO:

For this example, we will simply use an IMG tag:

On page load, we will call the method to choose the background image at random, but only if an image has not yet been selected this session.
The code-behind will look something like this:

Download Source Files