验证码图片未显示[无错误] [英] Captcha Image not showing[Error free]

查看:264
本文介绍了验证码图片未显示[无错误]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 http://www.codeproject.com/KB/aspnet/CaptchaImage.aspx上的指南进行操作. [ ^ ]
我已经重命名了我的命名空间,同时也注释掉了受保护的UI控件的3行.

JpegImage.aspx
内部的代码

I have followed the guide at http://www.codeproject.com/KB/aspnet/CaptchaImage.aspx[^]
I''ve renamed my namespace, comment out the 3 lines of protected UI controls also.

code inside JpegImage.aspx

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="JpegImage.aspx.cs" Inherits="CaptchaImage.JpegImage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Jpeg Image</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
    <form id="JpegImage" method="post" runat="server">
    </form>
</body>
</html>



JpegImage.aspx
后面的代码



the codes behind JpegImage.aspx

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace JoyConnectionApp
{
    public partial class JpegImage : System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Create a CAPTCHA image using the text stored in the Session object.
            CaptchaImage ci = new CaptchaImage(this.Session["CaptchaImageText"].ToString(), 200, 50, "Century Schoolbook");

            // Change the response headers to output a JPEG image.
            this.Response.Clear();
            this.Response.ContentType = "image/jpeg";

            // Write the image to the response stream in JPEG format.
            ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);

            // Dispose of the CAPTCHA image object.
            ci.Dispose();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
    }
}



我的主要形式 .cs



My main form .cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace JoyConnectionApp
{
    public partial class AddGuardian : System.Web.UI.Page
    {
        //protected System.Web.UI.WebControls.TextBox tbxCAPTCHA;
        //protected System.Web.UI.WebControls.Button Button1;
        //protected System.Web.UI.WebControls.Label lblANS;

        // For generating random numbers.
        private Random random = new Random();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)

                // Create a random code and store it in the Session object.
                this.Session["CaptchaImageText"] = GenerateRandomCode();
                
            else
            {
                // On a postback, check the user input.
                if (this.tbxCAPTCHA.Text == this.Session["CaptchaImageText"].ToString())
                {
                    // Display an informational message.
                    this.lblANS.CssClass = "info";
                    this.lblANS.Text = "Correct!";
                }
                else
                {
                    // Display an error message.
                    this.lblANS.CssClass = "error";
                    this.lblANS.Text = "ERROR: Incorrect, try again.";

                    // Clear the input and create a new random code.
                    this.tbxCAPTCHA.Text = "";
                    this.Session["CaptchaImageText"] = GenerateRandomCode();
                }
            }
        }
        // Returns a string of six random digits.
        //
        private string GenerateRandomCode()
        {
            string s = "";
            for (int i = 0; i < 6; i++)
                s = String.Concat(s, this.random.Next(10).ToString());
            return s;
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }



主页.aspx



The main page .aspx

<td class="style4">
&nbsp;</td>
<td colspan="2">
  &nbsp;<img src="JpegImage.aspx">
</td>

推荐答案



请访问以下文章

ASP.NET中的CAPTCHA图形 [投票":thumbsup:如果有帮助,请提供"接受答案",如果这是正确的答案.:rose:

谢谢,
Imdadhusen
Hi,

Please visit following Article

CAPTCHA Graphic in ASP.NET[^]

Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen


我已经解决了.感谢您的链接Imdadhusen.我的命名空间有误,这就是它没有通过的原因.
I''ve solved it already. Thanks for the link Imdadhusen. My namespace was wrong that''s why it didn''t go through.


这篇关于验证码图片未显示[无错误]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆