ASP.net 会员资格将数据保存在 2 个数据库中

发布于 2024-10-17 04:03:48 字数 1884 浏览 3 评论 0原文

在我们的应用程序中,我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小瓶盖 2024-10-24 04:03:48

您必须将配置文件提供程序配置为使用与其他两个提供程序相同的连接字符串。

<profile defaultProvider="CustomizedProfileProvider" >
  <providers>
    <clear/>
    <add name="CustomizedProfileProvider" connectionStringName="MyConnectionString" applicationName="App209" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
</profile>

You have to configure the profile provider to use your connection string the same as the other two providers.

<profile defaultProvider="CustomizedProfileProvider" >
  <providers>
    <clear/>
    <add name="CustomizedProfileProvider" connectionStringName="MyConnectionString" applicationName="App209" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
</profile>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文