The method that lets you sign out current users is the FormsAuthentication
class’s SignOut method. You could call this method in the Click event handler
of a Sign Out button, like this:
Visual Basic
Sub Logout(s As Object, e As EventArgs)
FormsAuthentication.SignOut()
Response.Redirect("Default.aspx")
C#
void Logout(Object s, EventArgs e) {
FormsAuthentication.SignOut();
Response.Redirect("Default.aspx");
}
As you can see, the SignOut method is used to clear the authentication cookie.
The next line simply redirects the user to the home page.
ASP.NET 2.0 Memberships and Roles
The ASP.NET 2.0 team made a big step forward by implementing common
functionality that previously needed to be coded from scratch for every new web
application. This functionality includes a membership system, which supports
the management of customer accounts, login forms, user registration forms, and
so on, and is divided into several layers, which can each be extended or modified
to suit your needs.
In particular, this new membership system offers a rich set of login controls,
which you find in the Login tab of the Toolbox in Visual Web Developer. That’s
right—you can add a form for the creation of new user accounts simply by dragging
a CreateUserWizard control into a web form! ASP.NET 2.0 makes implementing
many such features extremely easy, but in order to take full advantage of these
controls, we’ll need to learn about the framework on which they’re built.
Creating the Membership Data Structures
ASP.NET 2.0’s membership system stores user profile data, including membership
and personalization information, in a structured data store consisting of a set of
tables, views, and stored procedures. We’ll call these membership data struc-
tures, although that name doesn’t take into account the complete range of data
they contain.
544
Chapter 13: Security and User Authentication