Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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.net中从web表单的URL获取参数值?_C#_Asp.net - Fatal编程技术网

C# 如何在asp.net中从web表单的URL获取参数值?

C# 如何在asp.net中从web表单的URL获取参数值?,c#,asp.net,C#,Asp.net,我有一个问题,如何获得确切的个人id与电子邮件地址做重置密码。因此,从这里我将通过电子邮件向用户发送超链接 SmtpClient client = new SmtpClient(); try { SendPasswordResetEmail(u.EmailAddress.ToString(),u.Name.ToString(),UniqueID); lblMe

我有一个问题,如何获得确切的个人id与电子邮件地址做重置密码。因此,从这里我将通过电子邮件向用户发送超链接

            SmtpClient client = new SmtpClient();

            try
            {
                SendPasswordResetEmail(u.EmailAddress.ToString(),u.Name.ToString(),UniqueID);
                lblMessage.ForeColor = System.Drawing.Color.LimeGreen;
                lblMessage.Text = "Email has been successfully sent!";
            }
            catch (Exception exc)
            {
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text = "ERROR: " + exc.Message;
            }
然后这是我给用户的消息内容,以便让他们点击进入超链接

        string emailAddress = txtEmail.Text;

        User u=db.Users.Single(x => 
                            x.EmailAddress == emailAddress);

        MailMessage mailMessage = new MailMessage(u.EmailAddress, ToEmail);
        StringBuilder sbEmailBody = new StringBuilder();
        sbEmailBody.Append("Dear " + u.Name.ToString() + ",<br/><br/>");
        sbEmailBody.Append("Please click on the following link to reset your password");
        sbEmailBody.Append("<br/>"); sbEmailBody.Append("https://localhost:44305/Registration/ChangePwd.aspx?uid=" + u.Id);
        sbEmailBody.Append("<br/><br/>");
        sbEmailBody.Append("<b>吹水站</b>");

        mailMessage.IsBodyHtml = true;

        mailMessage.Body = sbEmailBody.ToString();
        mailMessage.Subject = "Reset Your Password";
        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

        MailMessage msg = new MailMessage();

        msg.To.Add(new MailAddress(txtEmail.Text));
        smtpClient.EnableSsl = true;
        smtpClient.Send(mailMessage);
string emailAddress=txtEmail.Text;
用户u=db.Users.Single(x=>
x、 EmailAddress==电子邮件地址);
MailMessage MailMessage=新邮件(u.EmailAddress,ToEmail);
StringBuilder sbEmailBody=新的StringBuilder();
sbEmailBody.Append(“亲爱的”+u.Name.ToString()+”,

); sbEmailBody.Append(“请单击以下链接重置密码”); sbEmailBody.Append(“
”);sbEmailBody.Append(“https://localhost:44305/Registration/ChangePwd.aspx?uid=“+u.Id); sbEmailBody.Append(“

”); sbEmailBody.Append(“吹水站"); mailMessage.IsBodyHtml=true; mailMessage.Body=sbEmailBody.ToString(); mailMessage.Subject=“重置密码”; SmtpClient SmtpClient=新的SmtpClient(“smtp.gmail.com”,587); MailMessage msg=新的MailMessage(); msg.To.Add(新邮件地址(txtEmail.Text)); smtpClient.EnableSsl=true; smtpClient.Send(mailMessage);
那么这就是我的ChangePwd.aspx?uid=pages

<form id="form1" runat="server">
    <div>
        <h1>Change password</h1>
    </div>
    <div>
        <asp:Literal ID="litEmailAddress" runat="server"></asp:Literal>
    </div>
    <div>
        <p>Enter new password : 
        <asp:TextBox ID="txtNewPwd" runat="server" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please fill in the blank" ControlToValidate="txtNewPwd" CssClass="error" Display="Dynamic"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtNewPwd" CssClass="error" ErrorMessage="Password must be between 8-16 characters including at least 1 letter and 1 number" ValidationExpression="((?=.*\d)(?=.*[a-z]).{8,16})"></asp:RegularExpressionValidator>
        </p>
    </div>
    <div>
        Re-enter new password:
        <asp:TextBox ID="txtRepeatPwd" runat="server" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please fill in the blank" ControlToValidate="txtRepeatPwd" CssClass="error" Display="Dynamic"></asp:RequiredFieldValidator>
        <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtNewPwd" ControlToValidate="txtRepeatPwd" CssClass="error" ErrorMessage="Password and repeat password are not matched"></asp:CompareValidator>
    </div>
    <p>
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="False" PostBackUrl="~/Registration/Login.aspx" /><asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClick="btnConfirm_Click" />
    </p>
    <div>
    <p><asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label></p>
    <asp:Label ID="lblFailed" runat="server" Text=""></asp:Label>
    </div>

</form>

更改密码
输入新密码:

重新输入新密码:


从这里开始,我不知道当他们单击ChangePwd.aspx的超链接进行重置时,如何获得准确的用户电子邮件地址。然后,我必须更新数据库以存储用户更新后的密码。我尝试在线搜索,但缺乏从internet获得的资源。任何人请帮助,谢谢。

您应该是一名可以使用
Request.QueryString
属性访问URL中指定的
uid
(即
Request.QueryString[“uid”]
)的值。然后可以直接获取具有
Id
User
对象并获取用户的电子邮件地址


这里是一个基本教程:

加载ChangePwd.aspx页面时,您需要唯一地标识用户,以便将新密码保存到该特定用户。这里您需要的是传递主id(用户id或电子邮件地址)从您的电子邮件发送到ChangePwd.aspx页面。通过将ID传递到URL查询字符串,您正在正确执行此操作

https://localhost:44305/Registration/ChangePwd.aspx?uid=" + u.Id);
现在,您需要在ChangePwd.aspx.cs(WebForm的服务器端类)中阅读这些内容

protected void Page_Load(object sender, EventArgs e)
{
   string userId= Request.QueryString["uid"];
   // get the user *User* from the database, using the above retrieved ID

   litEmailAddress.text = User.email; // something like this
}
现在,您可以将新密码保存到此用户。如果这有帮助或需要更多帮助,请告诉我