ASP.NET Web Pages - Account Management

[ This is an 8 part tutorial previous tutorial: logout and change password page ]

In the Manage file add the following:

var db = Database.Open("Membership");
var SQLCOMMAND = "SELECT Forename, Surname From Users Where UserId=@0";
var data = db.QuerySingle(SQLCOMMAND, WebSecurity.CurrentUserId);
var Forename = data.Forename;
var Surname = data.Surname;
var message= "";
if (IsPost)
    Forename = Request["Forename"];
    Surname = Request["surname"];
    Validation.RequireFields("Forename", "Surname");

As we store additional information about users, it is important to allow them to change it. In the code above we open the database and get the stored content for the current user. The First Name and Surname variables are global and hold the value of the currently stored data from the database until the user submits the form. The variables will have the user-submitted values.

    if (Validation.IsValid())
        var SQLUPDATE = "UPDATE Users set Forename=@0, Surname=@1 Where UserId=@2";
            db.Execute(SQLUPDATE, Forename, Surname, WebSecurity.CurrentUserId);
            message = "Updated!";
        }catch (Exception ex)
            message = ex.Message;

If the data is valid, update the data in the database.


<form method="post">
<legend>Manage Account</legend>
<input type="text" name="Forename" value="@Forename"/>
<input type="text" name="Surname" value="@Surname"/>
<input type="submit" value="Update Account"/>



Adding membership in ASP.NET Web Pages is quite simple, the WebSecurity Class provides you with many methods and properties that can be used to add this functionality to a website. In this tutorial we created a fairly complex membership system with account confirmation, reset password and additional user information. For more on WebSecurity Class see the reference.