ASP.NET 会员资格未填充新用户
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
web.config 中的 Profile 部分是否使用与 Membership 部分相同的 connectionStringName 值? 这是我要检查的第一件事。
编辑:您可以发布完整的配置文件配置块吗? 你应该有一些定义属性的东西,比如
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
除了
connectionStringName
之外,您可能还需要仔细检查applicationName
。 如果它们不匹配,或者您在一个部分而不是另一部分中定义应用程序名称,您将遇到问题。In addition to the
connectionStringName
, you may also want to double-checkapplicationName
. If they don't match, or you define the application name in one section and not the other, you'll run into issues.