Guid must contain 32 digits with four dashes

I had a website containing a createuserwizard control. And when you create an account, an email verification along with its verification URL will be sent to the user's email address.

However, when I have a trial run, after clicking on the URL in the email, this error appears:

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. 

Another fun thing: the validation url in my test mode looks weird:

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

Usually the URL should look like this (this is a lot of characters at the end of the URL:

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

I really thought there was a link to the end of the URL with my error problem (Guid should contain 32 digits with four dashes).

The code that generates the URL is as follows:

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

Please give me suggestions and what should I do to solve these problems.

.

UPDATE:

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 32 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

+5
4

, :

Guid userInfoId = (Guid)userInfo.ProviderUserKey;

, , URL-?

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

ID :

User.ToString()

:

"System.Security.Principal.GenericPrincipal"

GUID , , .

+3

, GUID, ID value=User.Tostring().

0

You must make two changes. First, as already mentioned, User.ToString()will always produce "System.Security.Principal.GenericPrincipal". You should change this to:

User.Guid.ToString()

Secondly, your web page should be more code protected and use TryParse, as in:

  Guid g;
  if (Guid.TryParse(Request.QueryString["ID"], out g))
    // its a good Guid
  else
    // its not a valid Guid
0
source

All Articles