Membership专题学习

(一) Membership数据表结构详细解释

   昨天收到《C#2005 &.NET 3.0高级编程(第5版)》,非常厚,有1500多页,分上下两册,里面的东西讲得非常详细,这本书对我而言具有非常重要的作用。《C#入门经典第三版》前面十章我看了两遍,读书百遍,其义自现,真理。已经对今年要看的编程方面的书做了计划,但是需要完善和进一步的细化。
    最近在研究ASP.NET2.0中的Membership,整理这些资料,以备用。
    此为第一篇:Membership 数据表结构的详细解释。

表名:aspnet_Applications

说明:保存应用程序信息

字段名

类型

属性

说明

 ApplicationName

 nvarchar(256)

 

 应用程序名

 LoweredApplicationName

 nvarchar(256)

 

 小写的应用程序名

ApplicationId

 uniqueidentifier

 PK

应用程序的id, GUID值

 Description

 nvarchar(256)

 nullable

应用程序的 描述

 

表名:aspnet_Paths

说明:路径信息

字段名

类型

属性

说明

 ApplicationId

 uniqueidentifier

 FK: appnet_Applications.ApplciationId

 应用程序Id

 PathId

 uniqueidentifier

 PK

 路径Id

 Path

 nvarchar(256)

 

 路径信息

 LoweredPath

 nvarchar(256)

 

小写的路径信息

表名:aspnet_Users

说明:用户信息

字段名

类型

属性

说明

 ApplicationId

 uniqueidentifier

 

 应用程序Id

 UserId

 uniqueidentifier

 PK

用户Id

 UserName

 nvarchar(256)

 

 用户名

 LoweredUserName

 nvarchar(256)

 

 小写的用户名

 MobileAlias

 nvarchar(16)

 

 移动电话的pin码(未使用)

 IsAnonymous

 bit

 

 是否为匿名用户

LastActivityDate

 datetime

 

 最后活动日期

 

表名:aspnet_Membership

说明:成员信息

字段名

类型

属性

说明

 ApplicationId

 uniqueidentifier

 FK: appnet_App

lications.

ApplciationId

 应用程序Id

 UserId

 uniqueidentifier

 FK: aspnet_Users.

UserID

用户Id

 Password

 nvarchar(128)

 

 密码

 PasswordFormat

 int

 

存储密码的格式 

 PasswordSalt

 nvarchar(128)

 

密码的Hash值

 MobilePIN

 nvarchar(16)

 

 手机PIN码

 Email

 nvarchar(256)

 

 电子邮件地址

 LoweredEmail

 nvarchar(256)

 

 小写的电子邮件地址

 PasswordQuestion

 nvarchar(256)

 

 遗忘密码问题

 PasswordAnswer

 nvarchar(128)

 

 遗忘密码答案

 IsApproved

 bit

 

 

 IsLockedOut

 bit

 

 是否锁住

 CreateDate

 datetime

 

 创建时间

 LastLoginDate

 datetime

 

 最后登录时间

 LastPassword

ChangedDate

 datetime

 

 最后密码更改时间

 LastLockoutDate

 datetime

 

 最后一次锁帐号的时间

 FailedPassword

AttemptCount

 int

 

 密码失败尝试次数

 FailedPassword

AttemptWindowStart

 datetime

 

 密码失败尝试窗口打开时间

 FailedPassword

AnswerAttemptCount

 int

 

 遗失密码问题尝试次数

 FailedPasswordAnswer

AttemptWindowStart

 datetime

 

 遗失密码问题输入窗口打开时间

 Comment

 ntext

 

 备注

 

表名:aspnet_Roles

说明:角色表

字段名

类型

属性

说明

ApplicationId

 uniqueidentifier

 FK: appnet_Applications.ApplciationId

应用程序Id

 RoleId

 uniqueidentifier

 PK

 角色Id

 RoleName

 nvarchar(256)

 

 角色名称

 LoweredRoleName

 nvarchar(256)

 

 小的角色名称

 Description

 nvarchar(256)

 nullable

 描述

 

表名:aspnet_UsersInRoles

说明:用户角色关系表

 字段名

 类型

属性

说明

 UserID

 uniqueidentifier

 FK: aspnet_Users.UserId

用户ID 

 RoleID

 uniqueidentifier

 FK: aspnet_Roles.RoleId

 角色ID

 

表名:aspnet_Profile

说明:Profile对象存储表

字段名

类型

属性

说明

 UserId

 uniqueidentifier

 FK: aspnet_Users.UserId

 用户ID

 PropertyNames

 ntext

 

 属性名称

 PropertyValuesString

 ntext

 

 字符串值

 PropertyValuesBinary

 image

 

 二进制值

LastUpdatedDate

 datetime

 

最后更新日期 

 

表名:aspnet_PersonalizationAllUsers

字段名

类型

属性

说明

 PathId

 uniqueidentifier

 FK: aspnet_Paths.PathId

 路径ID

 PageSetting

 ntext

 

 个性化设置

LastUpdatedDate

 datetime

 

最后更新日期 

表名:aspnet_PersonalizationPerUser

字段名

类型

属性

说明

Id

 uniqueidentifier

 PK

ID

PathID

 uniqueidentifier

FK: aspnet_Paths.PathId

路径ID

UserID

uniqueidentifier

FK:aspnet_Users.UserId

用户ID

 PageSetting

 ntext

 

 个性化设置

LastUpdatedDate

 datetime

 

最后更新日期 

 

(二)——membership应用到sqlserver2000/sqlserver2005 

  默认情况下membership在安装了 Sql Server Express 的情况下才能用,但是在多情况下我们的项目中已经有了自己的数据库,可能在sqlserver2000或者sqlserver2005,这时我们应当如何来使用membership所提供的功能呢?
   这个时候,就要手动地进行MemberShip的配置工作了。利用aspnet_regsql.exe这个工具就可以。
    首先,打开“Visual Studio 2005 命令提示”(在VS2005菜单里面的Visual Studio Tools里面能找到),运行aspnet_regsql.exe这个工具。然后按照屏幕提示,初始化数据库,你也可以直接在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\目录下找到可执行文件aspnet_regsql.exe,双击运行。(aspnet_regsql.exe所在具体位置可能与上面不同)

 

 


打开asp.net sqlserver安装向导:

如上图,配置好您的数据库服务器与数据库。
OK,打开数据库看下,如下图所示,已经安装了membership所需要的表:


  完成数据库的初始化工作之后,就需要对Web.Config进行相应配置。首先,确保在connectionStrings节里面已经配置好可以连接到该数据库的ConnectionString。如:
http://schemas.microsoft.com/.NetConfiguration/v2.0">

   

  接下来,配置membership节和roleManager节,这两个节都拥有providers子节,可以为他们创建多个 provider,每个provider都有connectionStringName的属性,这个属就是与上面connectionStrings相关联的。以下是示例:

http://schemas.microsoft.com/.NetConfiguration/v2.0">

   
     
       
                  name="SqlProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="northWindConn"
          applicationName="northWind"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="true"
          requiresUniqueEmail="true"
          passwordFormat="Hashed" />
     
   

   
     enabled="true"
     cacheRolesInCookie="true"
     cookieName=".ASPROLES"
     cookieTimeout="30"
     cookiePath="/"
     cookieRequireSSL="false"
     cookieSlidingExpiration="true"
     cookieProtection="All" >
     
                  name="SqlProvider"
          type="System.Web.Security.SqlRoleProvider"
          connectionStringName="northWindConn"
          applicationName="northWind" />
     
   


 关于web.config的详细配置说明请看下一篇文章.Net 2.0的MemberShip被设计为可以通地过一个数据库为多个应用程序提供MemberShip服务。不同的applicationName配置取得的资料是不同的,因此配置时需要注意前后提供的applicationName要一致。


(三)使用membership时对web.config的配置说明

   具体怎么在sqlserver2000中安装membership所需要的数据表、存储过程等,请查看这里《将ASP.NET中的membership应用到sqlserver2000/sqlserver2005中》
这里只详细说明对web.config的相关配置:
<connectionStrings>
    <add name="constrU" connectionString="server=.;database=aspnetdb;uid=sa;pwd=sa" providerName="System.Data.SqlClient" />
  </connectionStrings>
 
    <system.web>
      <membership defaultProvider="AspNetSqlMP">
        <providers>
          <add name="AspNetSqlMP"
                    type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                    connectionStringName="constrU" 
               enablePasswordRetrieval="false"
        enablePasswordReset="true"
        requiresQuestionAndAnswer="true"
        applicationName="/"
        requiresUniqueEmail="false"
        passwordFormat="Hashed"
        maxInvalidPasswordAttempts="5"
        minRequiredPasswordLength="6"
        minRequiredNonalphanumericCharacters="0"
        passwordAttemptWindow="10"
        passwordStrengthRegularExpression="" />
        </providers>
      </membership>
<system.web>

<!--
    connectionStringName 数据库连接。这个要在web.config设置
    enablePasswordRetrieval 获得一个值,指示当前成员资格提供程序是否配置为允许用户检索其密码。
    enablePasswordReset 获得一个值,指示当前成员资格提供程序是否配置为允许用户重置其密码。
    requiresQuestionAndAnswer 获取一个值,该值指示默认成员资格提供程序是否要求用户在进行密码重置和检索时回答密码提示问题。
    applicationName 获取或设置应用程序的名称。
    requiresUniqueEmail 指示用户在创建用户时是否必须提供唯一的电子邮件地址值。
    passwordFormat 指示在成员资格数据存储区中存储密码的格式。下面有详细说明
    maxInvalidPasswordAttempts 获取锁定成员资格用户前允许的无效密码或无效密码提示问题答案尝试次数。
    minRequiredPasswordLength 获取密码所要求的最小长度。
    minRequiredNonalphanumericCharacters 获取有效密码中必须包含的最少特殊字符数。
    passwordAttemptWindow 获取在锁定成员资格用户之前允许的最大无效密码或无效密码提示问题答案尝试次数的分钟数。

    对PasswordFormat 的详细说明
    属性指示存储密码的格式。密码可以采用 Clear、Encrypted 和 Hashed 密码格式存储。Clear 密码以明文形式存储,这可以提高存储和检索密码的性能,但安全性较差,当数据源安全性受到威胁时此类密码很容易被读取。Encrypted 密码在存储时进行了加密,可以在比较或检索密码时进行解密。此类密码在存储和检索时需要进行额外的处理,但比较安全,在数据源的安全性受到威胁时不容易被获取。Hashed 密码在存储到数据库时使用单向哈希算法和随机生成的 salt 值进行哈希处理。在验证某一密码时,将用数据库中的 salt 值对该密码进行哈希计算以进行验证。无法检索哈希密码。
    -->

posted @ 2008-09-12 14:23  么么茶.NET  阅读(659)  评论(0编辑  收藏  举报