ASP.NET 会员资格未填充新用户

发布于 2024-08-02 02:08:38 字数 3077 浏览 2 评论 0原文

我正在使用 ASP.NET 会员资格提供程序来处理当前网站上的所有会员活动。

我遇到了一个奇怪的问题。 如您所知,如果您熟悉 Asp.Net 成员资格,则数据存储在 ProfileCommon 中。

因此,您可以执行 ProfileCommon.UserId 来获取用户 ID。

这一切在我的生产服务器、临时服务器以及本地开发服务器上的旧帐户上都运行良好。

但是,如果我在本地开发服务器上创建一个新用户,则不会填充 Profilecommon 对象,并且会引发错误,因为页面引用 ProfileCommon.UserId ,并且它为空,从而引发异常。 用户已通过身份验证,但未填充 ProfileCommon。

有谁对为什么会发生这种情况有任何想法/建议?

编辑:这是我的 web.config 条目。 我不知道为什么我们删除 AspnetSqlProfileProvider 然后添加它。 这是我接管的网站,我还不是 100% 熟悉 asp.net 会员资格。

  <profile defaultProvider="AspNetSqlProfileProvider">
  <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="AspNetSqlProfileProvider"
         type="System.Web.Profile.SqlProfileProvider" 
         connectionStringName="ConnectionString"/>
</providers>

实际个人资料信息;

        <profile defaultProvider="SqlProfileProvider">
        <providers>
            <remove name="AspNetSqlProfileProvider"/>
            <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="FiftyMillionDBConnection"/>
        </providers>
        <properties>
            <add name="FirstName" type="String" serializeAs="String"/>
            <add name="LastName" type="String" serializeAs="String"/>
            <add name="EmailAddress" type="String" serializeAs="String"/>
            <add name="ScreenName" type="String" serializeAs="String"/>
            <add name="BirthDay" type="DateTime" serializeAs="String"/>
            <group name="Address">
                <add name="AddressLine1" type="String" serializeAs="String"/>
                <add name="AddressLine2" type="String" serializeAs="String"/>
                <add name="City" type="String" serializeAs="String"/>
                <add name="State" type="String" serializeAs="String"/>
                <add name="Zip" type="String" serializeAs="String"/>
            </group>
            <group name="PersonalInfo">
                <add name="Gender" type="String" serializeAs="String"/>
                <add name="Height" type="String" serializeAs="String"/>
            </group>
            <group name="OtherInfo">
                <add name="Agent" type="String" serializeAs="String"/>
                <add name="Employee" type="String" serializeAs="String"/>
                <add name="Source" type="String" serializeAs="String"/>
                <add name="EventRegistration" type="String" serializeAs="String"/>
            </group>
            <group name="AuthInfo">
                <add name="GUID" type="String" serializeAs="String"/>
                <add name="RegSource" type="String" serializeAs="String"/>
                <add name="ReceiveMail" type="String" serializeAs="String"/>
            </group>
        </properties>
    </profile>

谢谢你!

I'm using the ASP.NET Membership provider to handle all membership activities on my current site.

I've run into a weird problem. As you know, if you are familiar with Asp.Net membership, the data is stored in ProfileCommon.

So you could do ProfileCommon.UserId to get the userID.

This all works fine on my production server, my staging server and for old accounts on my local dev server.

However, if I create a new user on my local dev server, the Profilecommon object is not being populated and it is throwing errors because pages reference ProfileCommon.UserId for instance and it's null, thus throwing an exception. The user is Authenticated, but ProfileCommon is not being populated.

Does anyone have any ideas/suggestions as to why this might be happening?

Edit: here's my web.config entry. I'm not sure why we remove AspnetSqlProfileProvider then add it. This is a site I took over and I'm not 100% familiar with asp.net membership yet.

  <profile defaultProvider="AspNetSqlProfileProvider">
  <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="AspNetSqlProfileProvider"
         type="System.Web.Profile.SqlProfileProvider" 
         connectionStringName="ConnectionString"/>
</providers>

Actual profile info;

        <profile defaultProvider="SqlProfileProvider">
        <providers>
            <remove name="AspNetSqlProfileProvider"/>
            <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="FiftyMillionDBConnection"/>
        </providers>
        <properties>
            <add name="FirstName" type="String" serializeAs="String"/>
            <add name="LastName" type="String" serializeAs="String"/>
            <add name="EmailAddress" type="String" serializeAs="String"/>
            <add name="ScreenName" type="String" serializeAs="String"/>
            <add name="BirthDay" type="DateTime" serializeAs="String"/>
            <group name="Address">
                <add name="AddressLine1" type="String" serializeAs="String"/>
                <add name="AddressLine2" type="String" serializeAs="String"/>
                <add name="City" type="String" serializeAs="String"/>
                <add name="State" type="String" serializeAs="String"/>
                <add name="Zip" type="String" serializeAs="String"/>
            </group>
            <group name="PersonalInfo">
                <add name="Gender" type="String" serializeAs="String"/>
                <add name="Height" type="String" serializeAs="String"/>
            </group>
            <group name="OtherInfo">
                <add name="Agent" type="String" serializeAs="String"/>
                <add name="Employee" type="String" serializeAs="String"/>
                <add name="Source" type="String" serializeAs="String"/>
                <add name="EventRegistration" type="String" serializeAs="String"/>
            </group>
            <group name="AuthInfo">
                <add name="GUID" type="String" serializeAs="String"/>
                <add name="RegSource" type="String" serializeAs="String"/>
                <add name="ReceiveMail" type="String" serializeAs="String"/>
            </group>
        </properties>
    </profile>

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

疧_╮線 2024-08-09 02:08:38

web.config 中的 Profile 部分是否使用与 Membership 部分相同的 connectionStringName 值? 这是我要检查的第一件事。

编辑:您可以发布完整的配置文件配置块吗? 你应该有一些定义属性的东西,比如

<profile enabled="true">

    <properties>

        <add name="UserId" type="Int32"/>

        <add name="Gender" type="string"/>

        <add name="Age" type="Int32"/>

    </properties>

</profile>

Is the Profile section in web.config using the same connectionStringName value as the Membership section? This is the first thing I would check.

Edit: Can you post your full profile config block? You should have something that defines the properties like

<profile enabled="true">

    <properties>

        <add name="UserId" type="Int32"/>

        <add name="Gender" type="string"/>

        <add name="Age" type="Int32"/>

    </properties>

</profile>
尛丟丟 2024-08-09 02:08:38

除了 connectionStringName 之外,您可能还需要仔细检查 applicationName。 如果它们不匹配,或者您在一个部分而不是另一部分中定义应用程序名称,您将遇到问题。

   <membership defaultProvider="SqlProvider">
      <providers>
         <add name="SqlProvider"
          type="..."  
          connectionStringName="SomeConnString"
          applicationName="SomeApp"
          ...
          ... />
      </providers>
   </membership>

   <profile defaultProvider="ProfileProvider">
     <providers>
        <clear />
        <add name="ProfileProvider" 
            type="..." 
            applicationName="SomeApp"/>
     </providers>
     <properties>
        ...
     </properties>
  </profile>

In addition to the connectionStringName, you may also want to double-check applicationName. If they don't match, or you define the application name in one section and not the other, you'll run into issues.

   <membership defaultProvider="SqlProvider">
      <providers>
         <add name="SqlProvider"
          type="..."  
          connectionStringName="SomeConnString"
          applicationName="SomeApp"
          ...
          ... />
      </providers>
   </membership>

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