Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/10/2008, 04:34
Altear
 
Fecha de Ingreso: febrero-2008
Mensajes: 69
Antigüedad: 16 años, 3 meses
Puntos: 0
Respuesta: Impedir acceso automático

Ya conseguí hacerlo, por si alguien lo necesita les dejo el código que he utilizado, es un control ashx



//El código es el siguiente:
//Decimos al script que lo que devuelve por pantalla es una imagen:

context.Response.ContentType = "image/GIF";

//Creamos la imagen

Bitmap imagen_GIF = new System.Drawing.Bitmap(80, 30);
Graphics grafico = System.Drawing.Graphics.FromImage(imagen_GIF);
grafico.Clear(Color.Gainsboro);

//Definimos el tipo de fuente a utilizar

Font tipo_fuente = new Font("Baskerville Old Face", 13, FontStyle.Bold);

string randomNum = string.Empty;
Random autoRand = new Random();


//Generamos los numeros aleatorios que vamos a mostrar en la imagen
//Con letras insertadas al azar

for (int x = 0; x < 6; x++)
{
if ((autoRand.Next(0, 9)).ToString() == "0")
{
int i_letra = System.Convert.ToInt32(autoRand.Next(65, 90));

//Convertimos el numero obtenido en letra

string letra = ((char)i_letra).ToString();
randomNum += letra;

}
else
{
randomNum += System.Convert.ToInt32(autoRand.Next(0, 9)).ToString();
}
}

//Lo guardamos en una sesión para después verificar que se entra el numero correctamente.

context.Session["RandomNumero"] = randomNum;
grafico.DrawString(randomNum, tipo_fuente, Brushes.Black, 5, 5);


//Devolvemos el grafico.
imagen_GIF.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

tipo_fuente.Dispose();
grafico.Dispose();
imagen_GIF.Dispose();




* Codigo obtenido de netveloper.com