problem getting user via ProviderUserKey

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Hey

asp.net 3.5

I'm trying to develop a asp.net site which when user registers his profile
is not activated. He will receive a email containing a link he need to click
on to activate his profile

The problem is that when user click on the link, the code behind the link
don't find the user.

Here is some code:
protected void SendingMail(object sender, MailMessageEventArgs e)
{
CreateUserWizard cuw = (CreateUserWizard)sender;
MembershipUser user = Membership.GetUser(cuw.UserName);
Guid userId = (Guid)user.ProviderUserKey;
e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>",
CreateUserWizard1.Question);
e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>",
CreateUserWizard1.Answer);
e.Message.Body = e.Message.Body.Replace("<%link%>",
userId.ToString()); // Confirm.aspx?id=<%link%>
}

protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"] != null)
{
string d = Request["id"];
MembershipUser user = Membership.GetUser(Request["id"]);
if (user != null && user.IsApproved == false)
{
user.IsApproved = true;
Membership.UpdateUser(user);
}
}
}

The problem is with this line "MembershipUser user =
Membership.GetUser(Request["id"]);". The user object is still a NULL value,
so the if-block isn't run.

I use Form authentication

Any suggestions?
 
Can you please alaborate how you fixed this?

When we observed that for some(very less in fact) users, our forms
authentication based .NET application not letting them login.

When we checked we found that, the MembershipUser object getting set to null
for those usernames !!

Other usernames are getting validated and returning proper MembershipUser
objects.

A soon reply appriciated.

Thanks,
Mahavir
 
if (Request["id"] != null)
{
string d = Request["id"];
System.Guid UserGUID = new Guid(d);
MembershipUser user = Membership.GetUser(UserGUID);
if (user != null && user.IsApproved == false)
{
user.IsApproved = true;
Membership.UpdateUser(user);
}
}

regards,
www.uptothesky.com
 
Back
Top