random image generation in

Posted on 2010-01-07
Last Modified: 2012-05-08
Tthe following Errors occurs..
Error      1      'ASP.random_aspx.GetTypeHashCode()': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_p-tglsrj.0.cs      
Error      2      'ASP.random_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_p-tglsrj.0.cs      
Error      3      'ASP.random_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_p-tglsrj.0.cs      

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class Image : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        //Show the path to the folder which contains the files you wish to randomly select from
        string directory = "/RanImg/images";//"/common/images/random/";

        //Create a string array to contain the images
        string[] images = Directory.GetFiles(HttpContext.Current.Server.MapPath("images"));

        //Check to see if any images exist and if so display a random one
        if (images.Length > 0)
            int rnd = new Random().Next(0, images.Length);
            imgImage.ImageUrl = "~" + directory + "/" + Path.GetFileName(images[rnd]);

Open in new window

Question by:sunda2010
    1 Comment
    LVL 3

    Accepted Solution

    Hey mate, you code worked fine here.
    All I had to do was to remove the tilda ("~") on line 27 and point it at a real image directory.

    The only thing I can think of is that your site is running in the wrong version of .net. It's not much I know, but it might be worth double checking that and clearing your cache (C:\Windows\Microsoft.NET\[Framework version]\[.net version]\Temporary ASP.NET Files)

    Hope it helps

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now