Setting MembershipUser.IsApproved, how??

J

Jeff

ASP.NET 2.0

The code below doesn't set IsApproved to true. I mean that I've debugged
this code and usr.IsApproved actually get set to true. But when I quit the
application and in VS2005 I start "ASP.NET Configuration" then I still see
the user without the "active" column checked. To me it looks like
usr.IsApproved isn't saved back to the database, I thought the
MembershipUser automatically would do this?? What am I doing wrong here???

if (Request.QueryString["user"] != null)
{
string username = Request.QueryString["user"].ToString();
if (username.Length > 0)
{
MembershipUser usr = Membership.GetUser(username);
usr.IsApproved = true;
}
}

Jeff
 
G

Guest

Membership.UpdateUser(userObj) should have updated the user status.
Check to see if you are not over-riding the save anywhere else.

Just as a test, try to check the user-details after you set the IsApproved
to true.
Write it to the UI. And also check the db-call in your profiler to see if
its being passed the back-end.

The ASP.NET configuration mmc, i am not sure..i don't use it.

--
Sashidhar Kokku
ikaSystems Corp


Jeff said:
Hey

I used Membership.UpdateUser(usr); to save the updated MembershipUser



Jeff said:
ASP.NET 2.0

The code below doesn't set IsApproved to true. I mean that I've debugged
this code and usr.IsApproved actually get set to true. But when I quit the
application and in VS2005 I start "ASP.NET Configuration" then I still see
the user without the "active" column checked. To me it looks like
usr.IsApproved isn't saved back to the database, I thought the
MembershipUser automatically would do this?? What am I doing wrong here???

if (Request.QueryString["user"] != null)
{
string username = Request.QueryString["user"].ToString();
if (username.Length > 0)
{
MembershipUser usr = Membership.GetUser(username);
usr.IsApproved = true;
}
}

Jeff
 
Joined
Dec 14, 2008
Messages
1
Reaction score
0
Hi Jeff,

please don't forget to set the last activity date.
A small sample:

protected void Page_Load(object sender, EventArgs e)
{
foreach( string key in Request.QueryString )
{
if ( key == "uid" )
{
try
{
bool isApproved = false;

MembershipUserCollection users = Membership.GetAllUsers();

foreach( MembershipUser user in users )
{
if ( user.ProviderUserKey.ToString() != Request.QueryString[ key ] )
continue;

isApproved = true;

user.LastActivityDate = System.DateTime.UtcNow;
user.IsApproved = isApproved;

Membership.UpdateUser( user );

loginCtrl.UserName = user.UserName;
}

if ( ! isApproved )
Response.Write( "Benutzer konnte nicht genehmigt werden!" );
}
catch( System.Exception ex )
{
Response.Write( ex.ToString() );
Response.End();
}
}
}
}

To find out the logic behind the code classes you can take a look into the stored procedures.
In this case the stored procedure aspnet_Membership_UpdateUser.
The parameter @LastActivityDate never must be NULL.

Robert
 
Last edited:

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top