protected void Page_Load(object sender, EventArgs e)
{
chooseImage();
}
public string chooseImage()
{
if (Session["img"] == null)
{
string imgPath;
int fileCount = Directory.GetFiles(Server.MapPath("/media/img/"), "*.*", SearchOption.TopDirectoryOnly).Length;
fileCount = fileCount + 1;
imgPath = "media/img/" + RandomNumber(1, fileCount) + ".jpg";
Session["img"] = imgPath;
return imgPath;
}
else
return Session["img"].ToString();
}
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
}