激活用户注册 [英] Activation User Registration

查看:95
本文介绍了激活用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,

我一直试图通过在用户注册后点击电子邮件上的链接来实施确认/激活帐户。问题是在注册用户后获取邮件通知以激活帐户,但是当用户单击链接时,它会更改数据库上的任何内容。任何建议将不胜感激。谢谢







Hello Guys,
Ive been trying to implement the confirmation/activation account by clicking the link on email after the user registered. Problem is after registering the user get the mail notification to activate the account but when user click the link it dint change anything on the database. Any suggestion will be much appreciated.Thanks



//Activation link

private string GetUserID(string p)
{
    SqlCommand cmd = new SqlCommand("SELECT User_id From Auction_user_regist WHERE Email=@Email", con);
        cmd.Parameters.AddWithValue("@Email", tbxEmail.Text);
         if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            string User_id = Convert.ToString(cmd.ExecuteScalar());
            con.Close();
            cmd.Dispose();
            return User_id;
        }
    }


// is_approved code 

public partial class Account_is_approved : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ToString());
    SqlCommand cmd = new SqlCommand();
    string User_id,Email;

    protected void Page_Load(object sender, EventArgs e)
    {
           
if ((Request.QueryString["User_id"] != null) & (Request.QueryString["Email"] != null))
{
     User_id = Request.QueryString["User_id"];
     Email = Request.QueryString["Email"];
     SqlCommand cmd = new SqlCommand("UPDATE Auction_user_regist SET is_approved=1 WHERE User_id=@User_id AND Email=@Email", con);
     cmd.Parameters.AddWithValue("@User_id", User_id);
     cmd.Parameters.AddWithValue("@Email", Email);
     con.Open();
     cmd.ExecuteNonQuery();
     con.Close();
        }
    }
}

推荐答案

首先,采取 OriginalGriff的建议并改进你的问题,在这里添加代码而不是提供图像链接。



现在让我们来看看你的代码。根据您的代码,在激活页面加载页面上,它需要两个QueryString参数,它们是 User_id 电子邮件。因此,您的网址应包含这些内容。



网址可能类似于 - www.somewebsite.com/Activation.aspx?User_id=1&Email =something@some.com



请注意,我没有编码,您应该在将URL发送到用户的电子邮件时对其进行编码。



接下来,只需单击链接并调试代码即可。看看它是否正确执行。如果可能,还要记录异常。



但理想情况下,您应该在URL中包含这些信息,而只需添加一些激活码或用于识别用户的内容。请参阅 - 注册后发送用户确认电子邮件使用ASP.Net中的激活链接 [ ^ ]
First of all, take OriginalGriff's advice and improve your question to add codes here instead of giving image links.

Let's come to your code now. According to your code, on the Page Load of Activation Page, it requires two QueryString parameters they are User_id and Email. So, your URL should include these.

URL may be like - www.somewebsite.com/Activation.aspx?User_id=1&Email=something@some.com

Note that I have not encoded, you should encode the URL while sending it to the User's Email.

Next, just click on the link and debug your code. See if it correctly executing or not. Also log exceptions, if possible.

But ideally, you should include these information in URL, instead just add some activation code or something through which you can identify the User. Refer - Send user Confirmation email after Registration with Activation Link in ASP.Net[^]


这篇关于激活用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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