自定义aspnetdb数据库链接
来源:互联网 发布:12-13科比数据 编辑:程序博客网 时间:2024/05/15 11:53
自定义aspnetdb数据库
ASP.NET2.0中引用provider模式后,向membership roles prfile成员资格管理组件,就是以这种模式构建起来的,为程序的简化带来了极大的方便。要想灵活充分发挥它们的作用,需要自定义使用它们。今天看了一些这方面的文章,小有收获,把一些实用知识收集如下。
下面简要叙述在ASP.NET 2.0中使用SQL Server 2K/2K5做支持数据库的步骤:
在Visuaol Studio 2005的命令行环境中执行命令:aspnet_regsql。该工具可以为ASP.NET 2.0在指定的SQL Server上建立或指定一个支持数据库,默认名字为aspnetdb
接下来需要修改配置文件,可以在通过修改$:WINDOWS/Microsoft.NET/Framework/v2.0.50727/CONFIG/machine.config来实现,但修改machine.config文件并不是一个好的方法,好在ASP.NET 2.0提供了在Web.Config文件中修改的办法。
打开一个Web应用程序的Web.Config文件,添加如下配置节:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="server=(local);trusted_connection=false;user id=sa;pwd=8848;database=aspnetdb" providerName="System.Data.SqlClient" />
</connectionStrings>
首先用remove去掉在machine.config中定义的LocalSqlSever连接配置,那个连接是指向本地安装的Sql Express的;然后再重新添加一个LocalSqlServer数据库连接指向想要设定的Sql Server服务器数据库。
然后在<system.web>节点中去配置一个默认的使用LocalSqlServer数据连接的Provider,如下:
<system.web>
<membership defaultProvider="SqlMembershipProvider">
<providers>
<add connectionStringName="LocalSqlServer" name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
</system.web>
本人认为,可以只更改数据库链接串
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="server=GCL-506CBD461C4/SQLEXPRESS;trusted_connection=false;user id=sa;pwd=123456;database=aspnetdb" providerName="System.Data.SqlClient" />
</connectionStrings>
第4项可以不用更改,使用machine中原有的即可。使用clear命令清除继承的字符串。试验通过。
表名: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 最后更新日期
asp.net 2.0中扩展login控件
asp.net 2.0中,login登陆控件是个不错的选择,但有时需要扩展该控件,比如,在一个OA系统中,有时要选择登陆的用户所在的是集团的哪一个子公司,这样,除了用户名,密码外,还需要有个dropdownlist,设置为该集团的所有子公司名,象这样应该如何实现呢?
我们可以首先选择login control,并且将其转换为模版列,在其中加上一个dropdownlist,如下:
<asp:Login ID="Login1" runat="server" OnLoggingIn="Login1_LoggingIn">
<LayoutTemplate>
….
<asp:DropDownList id=”companies” runt=”server” …>
….
</asp:DropDownList>
….
</LayoutTemplate>
</asp:Login>
然后在login控件的Authenticate事件中,写入如下代码:
protected void Login1_ Authenticate (object sender, AuthenticateEventArgs e)
{
string company:
DropDownList companies = Login1.FindControl("companies ") as DropDownList;
if (companies != null)
company = companies.SelectedValue;
…
//Validate the user..
e.Authenticated = true;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sdwszl/archive/2007/04/21/1573902.aspx
- 自定义aspnetdb数据库链接
- 自定义aspnetdb数据库链接
- Windows Server2003 配置aspnetdb数据库
- AspNetDB数据库安装与配置
- AspNetDB.mdf数据库的建立和使用
- AspNetDB.mdf数据库的建立和使用
- asp.net中连不上数据库aspnetdb的问题
- 没有连接上aspnetdb.mdf数据库
- asp.net中连不上数据库aspnetdb的疑问
- ASPNETDB.MDF合并到自己的数据库
- AspNetDB.mdf数据库的建立和使用
- vb.net 自定义数据库链接类(Access)
- 可以让用户自定义动态链接数据库
- 可以让用户自定义动态链接数据库
- 在SQL2005正式版中使用ASPNETDB.MDF数据库
- 在SQL2005正式版中使用ASPNETDB.MDF数据库
- [资料]aspnetdb.mdf数据库的建立和使用
- 无法更新数据库 "***ASPNETDB.MDF",因为数据库是只读的”解决
- 顺溜电动车遮阳挡雨蓬赚钱
- linux下不错的下载软件——proz
- Str() 与 Cast() 和 Convert() 的区别
- 每天学一点 (4):CMenu的几个成员函数
- 你是家养的还是野生的?
- 自定义aspnetdb数据库链接
- 谈全球化软件测试和本地化测试
- 二零零九年经典雷人语录总汇四百零五条[转的]
- 《IT小小鸟》后记
- BCB 中OLE关闭Excel进程
- jQuery插件开发 - 其实很简单
- 整数因子分解(转)
- 如果要删除的行的主键值被其他表引用怎么办?
- 随笔a