-
Activation du compte
Bonjour à tous,
J'essaye dans mon application à envoyer un email de validation de compte à un utilisateur qui vient de s'inscrire à mon site web,j'ai cherché le code qui me permet de faire cela et j'ai trouvé le code suivant mais en vb.net
Code VB:
If String.IsNullOrEmpty(Request.QueryString("ID")) OrElse Not Regex.IsMatch(Request.QueryString("ID"), "[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}") Then
InformationLabel.Text = "An invalid ID value was passed in through the querystring."
Else
'ID exists and is kosher, see if this user is already approved
'Get the ID sent in the querystring
Dim userId As Guid = New Guid(Request.QueryString("ID"))
'Get information about the user
Dim userInfo As MembershipUser = Membership.GetUser(userId)
If userInfo Is Nothing Then
'Could not find user!
InformationLabel.Text = "The user account could not be found in the membership database."
Else
'User is valid, approve them
userInfo.IsApproved = True
Membership.UpdateUser(userInfo)
'Display a message
InformationLabel.Text = "Your account has been verified and you can now log into the site."
End If
End If
J'ai essayé de traduisez ce code en c# et j'ai obtenue le code suivant:
Code C#:
if ((String.IsNullOrEmpty(Request.QueryString("ID"))) || (Regex.IsMatch(Request.QueryString("ID"), "[0-9a-f]{8}\\-([0-9a-f]{4}\\-){3}[0-9a-f]{12}")) == true)
{
//Request.QueryString.ToString()
InformationLabel.Text = "An invalid ID value was passed in through the querystring.";
}
else
{
Guid userID = new Guid(Request.QueryString("ID"));
MembershipUser userInfo = Membership.GetUser(userID);
if (userID == 0)
{
InformationLabel.Text = "The user account could not be found in the membership database.";
}
else
{
userInfo.IsApproved = true; Membership.UpdateUser(userInfo); InformationLabel.Text = "Your account has been verified and you can now log into the site.";
}
}
le problème que lorseque je l'execute il me retourne l'erreur suivante:
'System.Web.HttpRequest.QueryString' est un 'propriété' mais est utilisé comme un 'méthode'
Merci
-
-
Request.QueryString est une propriété et tu ne peut pas récupérer l'ID par une propriété donc vous devez utilisé la méthode Get("ID"):
Request.QueryString.Get("ID")