Introduction
这篇文章示范了如何使用asp.net中的表单验证。我写了一些类和一个使用这些类的小型web应用程序作示例。这个程序重点写了四个pages以实现这些功能:增加用户,给用户指派角色,给用户移除角色及管理角色。虽然我写的这些类提供了足够使用的功能,但为演示,我限制了User类的字段。这意味着,用户新注册账户时将提供基本的字段如:全名,Email,密码,个人简介等。如果以后需要,你可以很容易地增加其它字段。
The Classes Overview
这里有User, Role, SitePrincipal和 SiteIdentity 四个类,下面是这些类的属性和方法:
The User class
|
Default parameter less constructor to create a new user
|
|
This constructor gets a userID and looks up the user details from the database
|
|
This constructor gets an email and looks up the user details from the database
|
|
This method returns a DataSet of all the users available in the database
|
|
This method returns a DataSet of roles assigned to the current user
|
|
This static method grabs the userID and returns a roles ArrayList assigned to that user
|
|
This method assigns a role to the current user
|
|
This method removes current user from the role that has been passed by the roleID.
|
|
Adds a new user to the database
|
|
Updates current user information
|
|
Deletes current user
|
|
Gets/Sets user's id number
|
|
Gets/Sets user's full name
|
|
Gets/Sets user's email
|
|
Gets/Sets user's password
|
|
Gets/Sets user's biography
|
|
Gets/Sets user's registering date
|
The Role class
|
Default parameter less constructor to create a new role
|
|
This constructor gets a roleID and looks up the role details from the database
|
|
This method returns a DataSet of all roles available in the database
|
|
Adds a new role to the database
|
|
Updates current role information
|
|
Deletes current role
|
|
Gets/Sets role ID number
|
|
Gets/Sets role name
|
The SitePrincipal class (implements the IIPrincipal Interface)
|
This constructor gets a userID and looks up details from the database
|
|
This constructor gets an email and looks up details from the database
|
|
(IIPrincipal.IsInRole()) Indicates whether a current principal is in a specific role
|
|
Adds a new user to the database
|