我有一个包含createuserwizard控件的网站.创建帐户后,验证电子邮件及其验证URL将发送到用户的电子邮件地址.
但是,当我进行测试运行时,单击电子邮件中的URL时会出现此错误:
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Source Error:
Line 17: {
Line 18: //store the user id
*Line 19: Guid userId = new Guid(Request.QueryString["ID"]);*
Line 20:
Error appeared on LINE 19.
Run Code Online (Sandbox Code Playgroud)
另一个有趣的事情是,我的测试运行中的验证URL看起来很奇怪:
http://localhost:4635/WebSite2/Verify.aspx?ID=System.Security.Principal.GenericPrincipal
Run Code Online (Sandbox Code Playgroud)
通常,URL应该是这样的(这是URL末尾的很多字符:
http://localhost:2180/LoginPage/EmailConfirmation.aspx?ID=204696d6-0255-41a7-bb0f-4d7851bf7200
Run Code Online (Sandbox Code Playgroud)
我实际上是在想,它与URL的结尾有一个连接我的错误问题(Guid应该包含32个数字,4个破折号).
生成URL的代码如下:
protected void CreateUserWizard1_SendingMail(object sender,MailMessageEventArgs e)
{
string domainName = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
string confirmationPage = "/Verify.aspx?ID=" + User.ToString();
string url = domainName + confirmationPage;
e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url);
}
Run Code Online (Sandbox Code Playgroud)
请给我建议以及我应该怎样做才能解决这个问题.
提前致谢.
更新:
protected void CreateUserWizard1_SendingMail(object sender,MailMessageEventArgs e)
{
MembershipUser userInfo = Membership.GetUser(CreateUserWizard1.UserName);
Guid userInfoId = (Guid)userInfo.ProviderUserKey;
string domainName = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
string confirmationPage = "/Verify.aspx?ID=" + userInfo.ToString();
string url = domainName + confirmationPage;
e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url);
}
Run Code Online (Sandbox Code Playgroud)
现在我的URL链接看起来像这样:
http://localhost:4635/WebSite2/Verify.aspx?ID=username
Run Code Online (Sandbox Code Playgroud)
但错误"Guid应包含32位数字,包括4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")仍然存在
你有一句话说:
Guid userInfoId = (Guid)userInfo.ProviderUserKey;
Run Code Online (Sandbox Code Playgroud)
这确实是您应该在 URL 中提供的内容吗?
string confirmationPage = "/Verify.aspx?ID=" + userInfoId.ToString();
Run Code Online (Sandbox Code Playgroud)