ASP.net 会员资格将数据保存在 2 个数据库中
在我们的应用程序中,我们使用 ASP.NET 会员数据库进行用户和角色管理。我们在现有的 SQL Express 数据库中安装了数据库表,一切工作正常。
后来在开发过程中,我们需要存储有关用户的附加信息,即:FullName
为此,我们在 web.config 中创建了一个配置文件,如下所示
<profile enabled="true">
<properties>
<add name="FullName" type="string"/>
</properties>
</profile>
:也有效,我们能够轻松添加和检索用户的全名。但令我们惊讶的是,我们发现数据库中的个人资料表是空的。经过进一步调查,我们发现个人资料信息没有保存在我们的常规 sqlexpress 数据库但保存在应用程序代码文件夹中的新 aspnetdb.mdf 中。
现在,每当我们创建新用户时,都会在两个数据库中创建它,但配置文件信息(即:全名)仅保存在 aspnetdb 中.mdf
有人可以回答为什么会发生吗...?
这是我们的 Web 配置的片段,其中我们明确指定需要使用我们自己的数据库而不是默认的 sqlmembershipprovider
<membership defaultProvider="CustomizedMembershipProvider">
<providers>
<clear/>
<add name="CustomizedMembershipProvider"
connectionStringName="MyConnectionString"
applicationName="App209"
commandTimeout="60"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
enablePasswordRetrieval="true"
enablePasswordReset="true"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="4"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
<roleManager enabled="true"
defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider"
connectionStringName="MyConnectionString"
applicationName="App209"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
有帮助吗? 提前致谢
In our application we are using asp.net membership database for user and role management. We installed the database tables in my existing SQL Express database and everything worked fine..
Later during development we were in need to store one additional information about the users ie:FullName
For this we created a profile in the web.config like this :
<profile enabled="true">
<properties>
<add name="FullName" type="string"/>
</properties>
</profile>
It also worked, we were able to add and retrieve the full name of the user easily.. But to our surprise we found that the profile table in our database is empty.. upon further investigation we found that the profile information is not being saved in our regular sqlexpress database BUT IS SAVED in a new aspnetdb.mdf in the app-code folder..
Now whenever we create a new user its being created in both databases but the profile information ( ie: Full Name) is saved only in the aspnetdb.mdf
Can someone answer why its happening... ??
Here is the snippet of our web config where we are explicitly specifying that our own database needs to be used and not the default sqlmembershipprovider
<membership defaultProvider="CustomizedMembershipProvider">
<providers>
<clear/>
<add name="CustomizedMembershipProvider"
connectionStringName="MyConnectionString"
applicationName="App209"
commandTimeout="60"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
enablePasswordRetrieval="true"
enablePasswordReset="true"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="4"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
<roleManager enabled="true"
defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider"
connectionStringName="MyConnectionString"
applicationName="App209"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
Any help?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将配置文件提供程序配置为使用与其他两个提供程序相同的连接字符串。
You have to configure the profile provider to use your connection string the same as the other two providers.