|
October 20, 2002 Forms-based Authentication Tips: October 2002
Yehuda Shiran, Ph.D.
|
|
ASP.NET includes the built-in class FormsAuthentication that provides static methods to handle authentication. The class belongs to the System.Web.Security namespace and cannot be inherited. This class provides the capability of forms-based authentication, which is unique to ASP.NET and was not provided by ASP. There are two advantages to forms-based authentication. First, you can customize the login UI. Using the ASP.NET forms-based authentication you have full flexibility over what the authentication page looks like. You can add the site's look-and-feel, user-oriented Help, or links to registration pages. The second advantage is that you can check the username and password using your Store database, as opposed to requiring an NT account for each user.
In order to use authentication, you first need to define which pages need authentication. You accomplish this with the
You specify the login page in Web.config with the <authentication> tag:
One of the methods of FormsAuthentication is RedirectFromLoginPage(). It redirects an authenticated user back to the originally requested URL. Here is how we use this in IBuySpy's Login.aspx:
Another method is SetAuthCookie() which creates an authentication cookie with the user ID in it. We use in IBuySpy's Register.aspx:
People who read this tip also read these tips: Look for similar tips by subject: |