如何向 MembershipProvider 添加属性
我想扩展额外的用户注册字段,其他教程建议的方法是使用配置文件属性。 (?)
所以我在 Web.config 文件中添加了一个部分,如下所示(标记),并且我期望 Profile 可以通过 .cs 文件中的智能感知使用,但事实并非如此。
那么如何使其工作呢?对此有更好的解决方案吗?
顺便说一句,教程是这个。
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<properties>
<add name="Age"/>
<add name="Gender" />
</properties>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
I want to extend additional user registration fields, and other tutorial suggested the way to do this is to use the profile-properties. (?)
So I add a section to the Web.config file, as shown below ( tag), and I expected Profile to be available by intellisense in the .cs files, but it's not..
So how to make this work? And are there better solutions to this?
Btw, the tutorial was this one.
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<properties>
<add name="Age"/>
<add name="Gender" />
</properties>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看
ProfileProvider
。它旨在针对MembershipUser
扩展其他属性。然后您可以对配置文件进行强类型访问。如果您使用的是网站项目,那么这是根据您的配置设置为您生成的代码。 Web 应用程序项目您需要手动执行此操作,或使用外部工具< /a>.这篇文章提供了一些有用的信息。
Have a look at
ProfileProvider
instead. It's designed to extend additional properties against theMembershipUser
.You can then strong type access to the Profile. If your are using the Web site project this is code generated for you from your config settings. Web Application project you need to do this manually, or use external tools. This article has some useful info.