Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在使用asp:login的asp.net登录表单中添加验证码?_C#_Asp.net_Asp.net Mvc_Login - Fatal编程技术网

C# 如何在使用asp:login的asp.net登录表单中添加验证码?

C# 如何在使用asp:login的asp.net登录表单中添加验证码?,c#,asp.net,asp.net-mvc,login,C#,Asp.net,Asp.net Mvc,Login,我正在使用asp:login对象进行登录,还使用成员安全性 我真的很困惑,因为当我想显示关于不正确登录和不正确验证码的消息时,它对我不起作用。 请告诉我一个简单的解决方案,我可以为每个错误设置消息 谢谢 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CatchpaRegistrationpage.aspx.cs" Inherits="Employee_CatchpaRegistrationpage" %>

我正在使用
asp:login
对象进行登录,还使用成员安全性
我真的很困惑,因为当我想显示关于不正确登录和不正确验证码的消息时,它对我不起作用。
请告诉我一个简单的解决方案,我可以为每个错误设置消息

谢谢


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CatchpaRegistrationpage.aspx.cs" Inherits="Employee_CatchpaRegistrationpage" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>

        <form id="form1" runat="server">

            <div>

                <asp:ScriptManager ID="SM1" runat="server">
                </asp:ScriptManager>

                <table style="border: solid 1px black; padding: 20px; position: relative; top: 50px;"
                    align="center">

                    <tr>

                        <td>EmailID :

                        </td>

                        <td>

                            <asp:TextBox ID="txtEmailID" runat="server" Width="200px"></asp:TextBox>

                        </td>

                    </tr>

                    <tr>

                        <td>Password :

                        </td>

                        <td>

                            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="200px"></asp:TextBox>

                        </td>

                    </tr>

                    <tr>

                        <td>Confirm Password :

                        </td>

                        <td>

                            <asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" Width="200px"></asp:TextBox>

                        </td>

                    </tr>

                    <tr>

                        <td>Enter Below Code :

                        </td>

                        <td>

                            <asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>

                        </td>

                    </tr>

                    <tr>

                        <td></td>

                        <td valign="middle">

                            <asp:UpdatePanel ID="UP1" runat="server">

                                <ContentTemplate>

                                    <table>

                                        <tr>

                                            <td style="height: 50px; width: 100px;">

                                                <asp:Image ID="imgCaptcha" runat="server" />

                                            </td>

                                            <td valign="middle">

                                                <asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />

                                            </td>

                                        </tr>

                                    </table>

                                </ContentTemplate>

                            </asp:UpdatePanel>

                        </td>

                    </tr>

                    <tr>

                        <td colspan="2" align="center">

                            <asp:Button ID="btnRegiser" runat="server" Text="Register" OnClick="btnRegister_Click" />

                        </td>

                    </tr>

                </table>

            </div>

        </form>

    </body>
    </html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;


public partial class Employee_CatchpaRegistrationpage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillCapctha();
        }
    }
    void FillCapctha()
    {
        try
        {
            Random random = new Random();
            string combination = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            StringBuilder captcha = new StringBuilder();
            for (int i = 0; i < 6; i++)
            {
                captcha.Append(combination[random.Next(combination.Length)]);
                Session["captcha"] = captcha.ToString();
                imgCaptcha.ImageUrl = "CatchpaRegistrationpage.aspx?" + DateTime.Now.Ticks.ToString();
            }
        }
        catch
        {
            throw;
        }
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        FillCapctha();
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (Session["captcha"].ToString() != txtCaptcha.Text)
        {
            Response.Write("Invalid Captcha Code");
        }
        else
        {
            Response.Write("Valid Captcha Code");
        }
        FillCapctha();
    }
}
EmailID: 密码: 确认密码: 输入以下代码: 使用制度; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.WebControl; 使用系统文本; 公共部分类员工注册页面:System.Web.UI.Page { 受保护的无效页面加载(对象发送方、事件参数e) { 如果(!IsPostBack) { FillCapctha(); } } void FillCapctha() { 尝试 { 随机=新随机(); 字符串组合=“0123456789abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyz”; StringBuilder验证码=新建StringBuilder(); 对于(int i=0;i<6;i++) { captcha.Append(组合[random.Next(组合.Length)]); 会话[“captcha”]=captcha.ToString(); imgCaptcha.ImageUrl=“CatchpaRegistrationpage.aspx?”+DateTime.Now.Ticks.ToString(); } } 抓住 { 投掷; } } 受保护的无效btnRefresh\u单击(对象发送者,事件参数e) { FillCapctha(); } 受保护的无效BTN注册表\u单击(对象发送者,事件参数e) { if(会话[“captcha”].ToString()!=txtCaptcha.Text) { 响应。写入(“无效验证码”); } 其他的 { 响应。写入(“有效验证码”); } FillCapctha(); } }
这里有一篇文章可以帮助您:谢谢@Sac,但我目前有验证码,我的问题是当我使用这种登录时,我可以显示验证码错误,但无法显示登录错误消息…您好。虽然您的代码可能会解决这个问题,但请对代码的功能进行一些说明。