problem getting user via ProviderUserKey

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?
 
M

Mahavir

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
 
K

Kazi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top