Learn how to a build a cloud-first strategyRegister Now


random image generation in asp.net

Posted on 2010-01-07
Medium Priority
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

Accepted Solution

Saber37886661 earned 500 total points
ID: 26207369
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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