|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
update more than only the email with asp.net membershipI am currently developing in asp.net 2.0 and I was at first impressed with the numerous login and user controls they provided to ease the task of managing users. But I am starting to think it's an hassle for certain tasks...here's my problem : I have created some users and successfully log them with the supplied controls. However, I have hard times with the 'user managment' screen (for the admin). On one page, I list all the users available in a Gridview. Up to there, everything works, great. However, I need to update the users information and I've tried the method suggested here (http://asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/security/Update.src), adapted to a gridview (with the RowUpdating event). But with the given method, I can only update the email!! what the &*$%......I can't change the Username nor the IsLockedOut values, because they are 'ReadOnly' properties. What does that mean? That I can't change them at all? How is the admin going to disable any users? I'd appreciate if someone can point me some resource that explain how to update user properties like username or locked status. This membership system is getting me mad. Thanks! :) ibiza Hello ibiza,
I'm not sure exactly what the problem is with your code but I noticed in the source from the Quickstart, that many of the bound items are marked as ReadOnly. If you change that property, then you should be able to change those fields (you probably already know this). My understanding is that if you go with the default membership data schema, everything is keyed off the username (an aspect that I disagree with. I feel that everything should be keyed off the email. But that's another story). I would assume that means you probably don't want to be mucking around with the username (they should probably be unique) and that's why they made the quickstart tutorial the way they did. Show quoteHide quote "ibiza" wrote: > Hi all, > > I am currently developing in asp.net 2.0 and I was at first impressed > with the numerous login and user controls they provided to ease the > task of managing users. > > But I am starting to think it's an hassle for certain tasks...here's my > problem : > > I have created some users and successfully log them with the supplied > controls. However, I have hard times with the 'user managment' screen > (for the admin). On one page, I list all the users available in a > Gridview. Up to there, everything works, great. However, I need to > update the users information and I've tried the method suggested here > (http://asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/security/Update.src), > adapted to a gridview (with the RowUpdating event). > > But with the given method, I can only update the email!! what the > &*$%......I can't change the Username nor the IsLockedOut values, > because they are 'ReadOnly' properties. What does that mean? That I > can't change them at all? How is the admin going to disable any users? > > I'd appreciate if someone can point me some resource that explain how > to update user properties like username or locked status. This > membership system is getting me mad. > > Thanks! :) > > ibiza > > Hi brians, thank you very much for your reply.
They made the bound items read only so the user cannot change them. However, being able to change them does not mean being able to update them. The real update is done here : Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e as DetailsViewUpdateEventArgs) 'Need to handle the update manually because MembershipUser does not have a 'parameterless constructor Dim memUser as MembershipUser = Membership.GetUser() memUser.Email = CStr(e.NewValues(0)) memUser.Comment = CStr(e.NewValues(1)) Try Membership.UpdateUser(memUser) e.Cancel = true DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) Catch ex as Exception Response.Write("<div>The following error occurred:<font color='red'> " + ex.Message + "</font></div>") e.Cancel = trueEnd Try End Sub The fact is, if you add for example : "memUser.IsLockedOut = True", it would throw an exception, as the property IsLockedOut from MembershipUser is read-only. So they only made the bound controls readonly because even if the user had the chance to change the data in textboxes, it could not be updated programatically because the MembershipUser object would not allow it. I can live, if I have to, with not being able to change the username, but gosh, I really need to lock/unlock users. Hi ibiza,
Just from a quick glance at the stored procedure aspnet_Membership_UpdateUser would lead me to believe that you don't want to be unlocking the user with the UpdateUser() method. But there is an aspnet_Membership_UnlockUser stored procedure which I would assume resolves to the MembershipUser.UnlockUser() method. You can probably use it to unlock the user. |
|||||||||||||||||||||||