c# - Guid 应包含 32 位数字和 4 个破折号

标签 c# asp.net

我有一个包含 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. 

另一个有趣的是,我的测试运行中的验证 URL 看起来很奇怪:

http://localhost:4635/WebSite2/Verify.aspx?ID=System.Security.Principal.GenericPrincipal

通常,URL 应该是这样的(URL 末尾有一大堆字符:

http://localhost:2180/LoginPage/EmailConfirmation.aspx?ID=204696d6-0255-41a7-bb0f-4d7851bf7200

我实际上在想,它与我的错误问题的 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); 
}

请给我建议以及我应该如何解决这个问题。

提前致谢。

更新:

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);

}

现在我的 URL 链接看起来像这样:

http://localhost:4635/WebSite2/Verify.aspx?ID=username

但是错误“Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”仍然存在

最佳答案

你有一行内容是:

Guid userInfoId = (Guid)userInfo.ProviderUserKey;

确定这是您应该在 URL 中提供的内容吗?

string confirmationPage = "/Verify.aspx?ID=" + userInfoId.ToString();

关于c# - Guid 应包含 32 位数字和 4 个破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11224493/

相关文章:

javascript - 从 ASP.NET Webforms 中的页面级别调用 UserControl 内部的客户端函数

c# - 我应该在 SQL 中还是在 LINQ 中执行 Where 子句?

asp.net - 授予 Asp.Net 用户帐户修改网站根目录的权限是否安全?

c# - 来自数据库的数据未返回,但正常列表是

c# - 如何删除网络安全创建的用户

c# - 为什么 NumberFormatInfo 中包含货币而不是其他单位

asp.net - 多个RegisterClientScriptBlock的

c# - 从 asp.net 网页中的 jQuery Ajax 调用检索 JSON 数组

c# - ToolStripItemCollection.AddRange 方法中的缺陷?

c# - 如何在给定角度的情况下找到椭圆上的点