Bonjour ....


Je veux mettre un captcha en place sur un formulaire d'enregistrement. Pour cela j'ai fais des recherches et j'ai trouvé des exemples sur le web ...

A cette occasion je découvre , via l'article de Nicolas HUMANN http://humann.developpez.com/httphandler/, les HttpHandler

Mais bon ...Ca marche pas et je ne sais pas pourquoi ..cela être bête comme chou mais je ne vois pas ...


Voici mon code :



1 Ma classe qui créer mon captcha :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.IO;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Drawing2D;
 
 
public class CaptchaHandler : IHttpHandler
{
 
	void captcha (string CheminSauvegarde)
	{
        ///============================================
        ///GENERATION ALEATOIRE DU CODE A 6 CARACTERES
        ///============================================
        Random Ran = new Random();
        string Str = "";
 
        string[] Alpha = {"a","b","c","d","e","f","g","h","i","j",
        "k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
        "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
        "Q","R","S","T","U","V","W","X","Y","Z","0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
 
        for (int i = 0; i <= 5; i++)
        {
            int intRanAlpha = Ran.Next(0, 61);
            Str = Str + Alpha[intRanAlpha].ToString();
        }
 
        Alpha = null;
        Ran = null;
 
 
        ///============================================
        ///CREATION IMAGE ET SAUVEGARDE
        ///============================================
 
        Bitmap Img = new Bitmap(85, 35, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        Graphics Gr = Graphics.FromImage(Img);
 
        SizeF sizeff = Gr.MeasureString(Str, new Font("Arial", 25, FontStyle.Strikeout, GraphicsUnit.Pixel), 300);
        HatchBrush hatchBrush = new HatchBrush(HatchStyle.Wave, Color.DarkBlue, Color.Gray);
        Gr.FillRectangle(hatchBrush, new Rectangle(0, 0, 85, 35));
        Gr.DrawString(Str, new Font("Arial", 15, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5);
        Img.Save(CheminSauvegarde);
 
	}
 
 
    public bool IsReusable
    {
        get
        {
            return true;
        }
    }
 
    public void ProcessRequest(System.Web.HttpContext context)
    {
        captcha("F:\\users\\web-inscriptions.fr\\httpdocs\\Captcha\\Capcha.jpg");
        System.Drawing.Image Img = System.Drawing.Image.FromFile("F:\\users\\web-inscriptions.fr\\httpdocs\\Captcha\\Capcha.jpg");
        Img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        Img.Dispose();
    }
 
}

Je précise que la partie qui génére le code , génere le fichier image et sauvegarde l'image marche. Elle a été testée dans des fonctions à part et fonctionne correctement, l'image est générée et sauvegardé dans le répertoire voulu ...Il n'y a pas de problème de droits ..( ...il n'y a plus...)

Comme expliqué dans le tutoriel sur les httpHandlers j'ai rajouté cette directive à mon web.config

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<httpHandlers>
<add path="Captcha.axd" verb="*" type="CaptchaHandler" validate="true"/>
</httpHandlers>

Voici ma balise sur ma page :

<img src="Captcha.axd" alt="" />


voila ...J'ai mon fichier image mais il ne s'affiche pas dans ma page ...Il n'y a pas de message d'erreur ...


Je cale ...