Randomly mapping an image in C# ASP.NET
<p>Quite a bit of looking at this one.</p>

<p>I have an aspx web page with an Image control on it, and I want to load images from my web directory at random to diplay in the image control. The below is the code and how far I have got.</p>

<p>Seems a simple task to request an image file at random and display this in a web page, all I am receiving however is a local filepath (which appears to be no use to the Image Control) and no image on the webpage.</p>

<p>AppSettings.imageUrl returns: "~/Images"</p>

<p>Any suggestions would be appreciated.</p>

<pre><code>        protected void Page_Load(object sender, EventArgs e)
    {
        GetImage();
    }

    private void GetImage()
    {

        imgMain.ImageUrl = ResolveClientUrl(RandomImage());

    }
    private string RandomImage()
    {
        string mapPath = Request.MapPath(AppSettings.imageUrl);

        var rand = new Random();
        var files = Directory.GetFiles(mapPath);
        return files[rand.Next(files.Length)];
</code></pre>
