简体   繁体   English

命名空间“ <global namespace> &#39;已经包含&#39;Handler&#39;的定义

[英]The namespace '<global namespace>' already contains a definition for 'Handler"

This HTml Code 此HTml代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Capctha Image with Refresh Button</title>
    <script type="text/javascript">
        function RefreshCaptcha() {
            var img = document.getElementById("imgcaptcha");
            img.src = "Handler.ashx?query=" + Math.random();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <img src="Handler.ashx" id="imgcaptcha" />
    <a href="#" onclick="javascript:RefreshCaptcha();">Refresh</a>
    </form>
</body>
</html>>

Captcha.aspx.cs Captcha.aspx.cs

using System.Drawing;
using System.Drawing.Imaging;

public class Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        using (Bitmap b = new Bitmap(200, 50, PixelFormat.Format32bppArgb))
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                Rectangle rect = new Rectangle(0, 0, 150, 40);
                g.FillRectangle(Brushes.White, rect);

                //Creating String Draw
                Random r = new Random();
                int StartIndex = r.Next(1, 5);
                int Length = r.Next(5, 15);
                string DrawString = Guid.NewGuid().ToString().Replace("-", "0").Substring(StartIndex, Length);


                //Creating Fount and Bursh
                Font drawFont = new Font("Arial", 16, FontStyle.Italic | FontStyle.Strikeout);

                using (SolidBrush drawBrush = new SolidBrush(Color.Blue))
                {
                    // Create point for upper-left corner of drawing.
                    PointF pointdraw = new PointF(10, 15);
                    // Draw string to screen.
                    g.DrawRectangle(new Pen(Color.Blue, 0), rect);
                    g.DrawString(DrawString, drawFont, drawBrush, pointdraw);
                }

                b.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                context.Response.ContentType = "image/jpeg";
                context.Response.End();
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    }

I am Getting Erros The namespace '' already contains a definition for 'Handler" like this how Can solve it and Give any idea about error and i am adding handler.ashx 我正在得到Erros命名空间''已经包含了'Handler'的定义,如下所示:如何解决它并给出有关错误的任何想法,我正在添加handler.ashx

Do you get this error upon compile-time or run-time? 在编译时或运行时会收到此错误吗?

This error usually occurs at compile-time and suggests that there is another Page/Handler/UserControl/ServerControl with the class-name Handler . 此错误通常在编译时发生,表明存在另一个具有类名Handler Page / Handler / UserControl / ServerControl。

Also looking at your structure, things are really wired: 还要查看您的结构,事情真的很紧密:

  • Captcha.aspx holds HTML code (but, I do believe so, points via directive to Captcha.aspx.cs ) Captcha.aspx保存HTML代码(但是,我确实相信,通过指令指向Captcha.aspx.cs
  • Captcha.aspx.cs holds the class Handler (which implements System.Web.IHttpHandler but rather should be a System.Web.UI.Page ) Captcha.aspx.cs拥有Handler类(它实现System.Web.IHttpHandler ,而应该是System.Web.UI.Page

Summing it up: I believe there's a flaw with the referencing. 总结:我相信引用存在缺陷。 The content of Captcha.aspx.cs is wrong and possibly a duplicate of a Handler.ashx.cs -file ... Captcha.aspx.cs的内容错误,并且可能是Handler.ashx.cs -file的重复...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM