`
jiasongmao
  • 浏览: 646373 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

aspnetdb.mdb数据库介绍

阅读更多

说明:该博文非原创,摘自:CSDN--->http://blog.csdn.net/pwalai/archive/2008/05/10/2431273.aspx

 

asp.net 安全性验证中,觉得最用的上就是Form验证 而2.0自带了一个aspnetdb 提供用户验证、授权、访问控制,总结、摘抄了一些如下。

一aspnetdb数据库中表结构

表名: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_Applications.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  最后登录时间
 LastPasswordChangedDate  datetime  最后密码更改时间
 LastLockoutDate  datetime  最后一次锁帐号的时间
 FailedPasswordAttemptCount  int  密码失败尝试次数
 FailedPasswordAttemptWindowStart  datetime  密码失败尝试窗口打开时间
 FailedPasswordAnswerAttemptCount  int  遗失密码问题尝试次数
 FailedPasswordAnswerAttemptWindowStart  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_Users.UserId
 用户ID
 PropertyNames  ntext  属性名称
 PropertyValuesString  ntext  字符串值
 PropertyValuesBinary  image  二进制值
LastUpdatedDate
 datetime 最后更新日期 

 

 

 

表名:aspnet_PersonalizationPerUser
说明:对特定用户的个性化设置

字段名
类型  属性  说明 
 PathId  uniqueidentifier  FK: aspnet_Users.UserId
 用户ID
 PropertyNames  ntext  属性名称
 PropertyValuesString  ntext  字符串值
 PropertyValuesBinary  image  二进制值
LastUpdatedDate
 datetime 最后更新日期 

 

aspnet_WebEvent_Events表:记录数据操作的事件日志(可由SqlWebEventProvider启用)。
aspnet_SchemaVersions表:为数据库中的各个部分设置的版本

 

aspnet_Application 应用程序表表:
每个Provider都有一个ApplicationName属性,该属性一般定义在web.config中,最常见就是网站根目录“\”,如图中作为最基本的表,创建后就不要修改了。
一个ProfileProvider的例子(其余3个Provider也一样):

<system.web>
...
<connectionStrings>
<add name="SqlSrvConnectionString" connectionString="..."/>
</connectionStrings>
...
<profile defaultProvider="SqlSrvProfileProvider">
<providers>
<add name="SqlSrvProfileProvider"
type="System.Web.Security.SqlProfileProvider"
connectionStringName="SqlSrvConnectionString" 
applicationName="WebShop" !!!!!
commandTimeout="30" 
description="SqlSrvProfileProvider" />
</providers>
<properties>
...
</properties>
</profile>
...
</system.web> 

这样你就为你的应用程序注册了一个"WebShop"名称
(也可以不明确配置applicationName值,默认为应用程序的虚拟根路径,即"/")。
要注意的是如果你那天把"WebShop"改成了"WebShop1"
(改成"webshop"、"webShop"等就和没改一样,因为应用程序名称是不区分大小写的),
你以前的用户自定义属性值就人间蒸发了,因为ProfileProvider把"WebShop1"
当作一个新的应用程序又新注册了一遍

 

aspnet_Users 基本用户表
不知各位DBA兄弟有没看出这个表与它的几个从表的关系,有点不太“讲道理”,
居然有2个一对一的关系(aspnet_Membership、aspnet_Profile)。“为什么不合并?不知道第3范式啊?”,老小弟
以前想装文化人的时候,总是这样吓唬小小弟的。若干年后,当老小弟看了几本
架构/模式的书,自我扫盲之后,才知道其实这是ORM模式中的一种。

另外,微软工程师这样设计还是非常巧妙的。在将公有部分提成几张基本表后,
数据库关系图4个部分就可合可分了。你可以试着在数据库关系图盖掉某几个部分,
剩下的部分仍然能够成一个完整的系统。
最后再交待一下IsAnonymous和LastActivityDate两个字段。
因为个性化用户配置和页面个性化设置能够支持匿名用户,所以该表中也会存在匿名用户,
IsAnonymous字段就是指示用户是否为匿名用户的标志字段。
LastActivityDate字段记录用户最后活动时间。该字段十分重要,每次成功的操作都会更新它,
同时它也是判断用户是否为非活动用户的依据之一。很多存储过程都会用到它。

 

aspnetdb 默认在app_data 新建sql express数据库,很不方便,可以独立出来到sql server2000 sqlserver 2005

1.%WINDOWS%Microsoft.NET\Framework\版本号\aspnet_regsql.exe 数据库配置向导

2.修改web.config
<connectionStrings>
<add name="qtsql" connectionString="server=localhost; uid=sa ;pwd=; database=aspnetdb;"/> 
</connectionStrings> 
=================
先添加个连接字符串



<membership defaultProvider="MySqlMembershipProvider">
<providers>
<add connectionStringName="qtsql" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true"
applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" name="MySqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>

 

上方代码就是添加驱动,就像1楼数据库图有4个功能,所以分别有四个驱动,可以在%WINDOWS%Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config找到模板,
applicationName就是应用程序名
connectionStringName="qtsql" 和尚数据库连接字符串对应
name为名称 4个驱动的name最好一致


3.vs2005中有asp.net 配置页面 修改提供程序为上name。
在asp.net 配置页面还可以添加用户 角色 规则 
实现4大部分中角色管理、成员资格管理部分

 

4大部分(3):用户个性化配置部分
由此表结构可以看出,所有的用户自定义属性最后都是“打包”(序列化)成一个或两个数据块,
存放在PropertyValuesString(序列化为string、Xml) 和(或) PropertyValuesBinary(序列化为Binary)
两个(或其中之一)字段中,因此要求用户自定义属性必须支持序列化。

序列化方式可由web.config中的serializeAs指定,SqlProfileProvider默认序列化方式为String。

例如用户在web.config中配置了如下自定义属性,这里的serializeAs="String" 仅仅为了表示
可以用户可以自行指定序列化方式,谢不写是一个样的:

<system.web>
...
<connectionStrings>
<add name="SqlSrvConnectionString" connectionString="..."/>
</connectionStrings>
...
<profile defaultProvider="SqlSrvProfileProvider">
<providers>
...
</providers>
<properties>
<add name="ThemeName" type="System.String" serializeAs="String" />
<group name="addPersonalInfo">
<add name="FirstName" type="System.String" serializeAs="String" />
<add name="LastName" type="System.String" serializeAs="String" />
<add name="Birthday" type="System.DateTime" serializeAs="String" />
</group>
</properties>
</profile>
...
</system.web> 

并运行了aspx页面中的以下C#代码:

this.Profile.ThemeName = "Blue"; 
this.Profile.PersonalInfo.FirstName = "John"; 
this.Profile.PersonalInfo.LastName = "Smith"; this.Profile.PersonalInfo.Birthday = new DateTime(1970, 11, 22);

然后打开数据库中的aspnet_Profile查看表,两个字段的内容分别为:
PropertyNames: "PersonalInfo.FirstName:S:0:4:PersonalInfo.Birthday:S:4:81:PersonalInfo.LastName:S:85:5:ThemeName:S:90:4:"
PropertyValuesString:"John 1970-11-22T00:00:00SmithBlue"

 

4大部分(4):页面个性化设置部分
有3个表:
页面路径(地址)表:aspnet_Paths
处于共享范围(Shared Scope)的页面个性化设置表:aspnet_PersonalizationAllUsers
处于单用户范围(User Scope)的页面个性化设置表:aspnet_PersonalizationPerUser

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics