SqlMembershipProvider.UpdateUser Method
Assembly: System.Web (in system.web.dll)
'Declaration Public Overrides Sub UpdateUser ( _ user As MembershipUser _ ) 'Usage Dim instance As SqlMembershipProvider Dim user As MembershipUser instance.UpdateUser(user)
public void UpdateUser ( MembershipUser user )
public override function UpdateUser ( user : MembershipUser )
Not applicable.
Parameters
- user
A MembershipUser object that represents the user to update and the updated information for the user.
| Exception type | Condition |
|---|---|
|
user is a null reference (Nothing in Visual Basic). - or - The UserName property of user is a null reference (Nothing in Visual Basic). - or - The Email property of user is a null reference (Nothing in Visual Basic) and RequiresUniqueEmail is set to true. | |
|
The UserName property of user is an empty string (""), contains a comma, or is longer than 256 characters. - or - The Email property of user is longer than 256 characters. - or - The Email property of user is an empty string and RequiresUniqueEmail is set to true. | |
|
The UserName property of user was not found in the database. - or - The Email property of user was equal to an existing e-mail address in the database and RequiresUniqueEmail is set to true. - or - The user update failed. |
This method is called by the Membership class to update user information for a user in the SQL Server database specified in the ASP.NET application's configuration file (Web.config). The Email, Comment, IsApproved, LastLoginDate, and LastActivityDate property values are updated for the specified membership user.
The maximum length for the UserName property is 256 characters. The maximum length for the Email property is 256 characters.
The password for a membership user cannot be updated using the UpdateUser method. To update the password for a membership user, use the ChangePassword method of the MembershipUser class.
The following code example updates the e-mail address for a user.
Note: |
|---|
|
This example uses the Membership class to call the SqlMembershipProvider specified as the defaultProvider in the Web.config file. If you need to access the default provider as the type SqlMembershipProvider, you can cast the Provider property of the Membership class. To access other configured providers as a specific provider type, you can access them by their configured name with the Providers property of the Membership class and cast them as the specific provider type. |
<%@ Page Language="vb" %> <%@ Import Namespace="System.Web.Security" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Dim u As MembershipUser Public Sub Page_Load(sender As Object, args As EventArgs) u = Membership.GetUser(User.Identity.Name) If Not IsPostBack Then EmailTextBox.Text = u.Email End Sub Public Sub UpdateEmailButton_OnClick(sender As Object, args As EventArgs) Try u.Email = EmailTextBox.Text Membership.UpdateUser(u) Msg.Text = "User e-mail updated." Catch e As System.Configuration.Provider.ProviderException Msg.Text = e.Message End Try End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Sample: Update User E-Mail</title> </head> <body> <form id="form1" runat="server"> <h3>Update E-Mail Address for <%=User.Identity.Name%></h3> <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br /> <table cellpadding="3" border="0"> <tr> <td>E-mail Address:</td> <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td> <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server" ControlToValidate="EmailTextBox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td> </tr> <tr> <td></td> <td><asp:Button id="UpdateEmailButton" Text="Update E-mail" OnClick="UpdateEmailButton_OnClick" runat="server" /></td> </tr> </table> </form> </body> </html>
Note: