SqlMembershipProvider.UpdateUser Method
Updates information about a user in the SQL Server membership database.
Assembly: System.Web (in System.Web.dll)
Parameters
- user
- Type: System.Web.Security.MembershipUser
A MembershipUser object that represents the user to update and the updated information for the user.
| Exception | Condition |
|---|---|
| System.ArgumentNullException | user is Nothing. - or - The UserName property of user is Nothing. - or - The Email property of user is Nothing and RequiresUniqueEmail is set to true. |
| System.ArgumentException | 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. |
| System.Configuration.Provider.ProviderException | 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>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note