千家信息网

asp.net注册页如何实现激活邮箱验证

发表于:2024-09-23 作者:千家信息网编辑
千家信息网最后更新 2024年09月23日,小编给大家分享一下asp.net注册页如何实现激活邮箱验证,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!---------
千家信息网最后更新 2024年09月23日asp.net注册页如何实现激活邮箱验证

小编给大家分享一下asp.net注册页如何实现激活邮箱验证,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

-----------注册页前台

复制代码 代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registe.aspx.cs" Inherits="CSDN博客.Registe" %>















































































*用户名:

ErrorMessage="用户名不能为空" ControlToValidate="txtName" Display="Dynamic"
Font-Size="15px" ForeColor="Red">


*密码:

ControlToValidate="txtPassword" Display="Dynamic" ErrorMessage="不能为空"
Font-Size="15px" ForeColor="Red">


*再次输入密码:

ControlToValidate="txtPassword" Display="Dynamic" ErrorMessage="不能为空"
ForeColor="Red" Font-Size="15px">

ErrorMessage="两次输入的密码不一致" ControlToCompare="txtPassword"
ControlToValidate="txtPasswordAgain" Display="Dynamic" ForeColor="Red"
Font-Size="15px">

*E-mail

ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="不能为空"
ForeColor="Red" Font-Size="15px">

ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="邮箱格式不正确"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ForeColor="Red" Font-Size="15px">


*校验码:

图片看不清?点击重新得到验证码
ControlToValidate="TextBox5" Display="Dynamic" ErrorMessage="不能为空">

(如您连续输入不对验证码,请检查您的浏览器是否禁用了Cookie。如何启用Cookie?
*注册条款:
oncheckedchanged="CheckBox1_CheckedChanged" Text="我已仔细阅读并接受" />CSDN注册条款

ImageUrl="~/images/zhuce.jpg" onclick=ImageButton1_Click" />
















------------激活验证

复制代码 代码如下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace CSDN博客
{
public partial class cheng : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//取出参数id
int id = Convert.ToInt32(Request["id"]);
string activeCode = Request["activecode"].ToString();
//2判断id为id的记录是否存在
//连接数据库
string conStr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=Blogs;user id=sa;password=admin";
int number;
using (SqlConnection con = new SqlConnection(conStr))
{
string sql = "select count(*) from T_User where Id=@id";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
cmd.Parameters.AddWithValue("@id", id);
number = Convert.ToInt32(cmd.ExecuteScalar());
}
}
if (number > 0)
{
//如果该用户存在取出ActiveCode字段进行比较。如果一样,把Active字段修改为true
//连接数据库
string AC;
using (SqlConnection con = new SqlConnection(conStr))
{
string sql = "select ActiveCode from T_User where Id=@id";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
cmd.Parameters.AddWithValue("@id", id);
AC = cmd.ExecuteScalar().ToString(); ;
}
}
if (activeCode == AC)
{
Response.Write("激活成功!返回登录");
using (SqlConnection con = new SqlConnection(conStr))
{
string sql = "update T_User set Active=1 where Id=@id";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
cmd.Parameters.AddWithValue("@id", id);
number = Convert.ToInt32(cmd.ExecuteScalar());
}
}
}
else
{
Response.Write("用户已存在,但是激活码错误!");
}
}
else
{
Response.Write("用户不存在,还没注册成功!");
}
}
}
}


实现如下效果:

以上是"asp.net注册页如何实现激活邮箱验证"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0