从 web.config 读取会员资格部分
我创建了一个自定义 MembershipProvider 类,到目前为止一切顺利,但是,我不确定如何从 web.config 文件中读取配置设置。
我尝试从 Google 和 Stackoverflow 进行搜索,似乎有人也遇到了我的问题 问题并询问,但没有给出答案。
这应该是一件简单的事情,但我在 Web 开发方面非常陌生,因此从 web.config 读取设置对我来说似乎太技术性了。
这是我的设置:
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="Test.Models.CustomMembershipProvider,Test"
passwordFormat="Hashed"
connectionStringName="ApplicationServices"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
maxInvalidPasswordAttempts="5"
enablePasswordReset="false"
enablePasswordRetrieval="false"
requiresQuestionAndAnswer="false"
applicationName="/"/>
</providers>
</membership>
我想阅读 minRequiredPasswordLength
设置,请协助。
I have created a custom MembershipProvider class, so far so good, however, I am not sure how to read the configuration settings from the web.config file.
I tried to search from Google and Stackoverflow, seems like someone also experiencing my
problem and asked, but no answer has been given.
It should be a simple thing, but I am very new in web development, so reading settings from web.config seems away too technical to me.
Here is my settings:
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="Test.Models.CustomMembershipProvider,Test"
passwordFormat="Hashed"
connectionStringName="ApplicationServices"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
maxInvalidPasswordAttempts="5"
enablePasswordReset="false"
enablePasswordRetrieval="false"
requiresQuestionAndAnswer="false"
applicationName="/"/>
</providers>
</membership>
I would like to read the minRequiredPasswordLength
setting, please assist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是代码中的解决方案:
here is the solution in code :
由于这被设置为您的默认提供程序,因此应该足以:
并且这将返回一个 int 指定所需的最小密码长度。
As this is set as your default provider it should be enough to:
And that would return an int specifying the minimum required password length.
如果您在自己的类中重写了 System.Web.Security.MembershipProvider ,则只需调用 System.Web.Security.Membership 即可按照 Robban 的建议获取 web.config 成员资格设置方法。但是,这些调用将定向到您的成员资格提供程序类,因此您需要提供一些实现。
假设您已重写
MembershipProvider
类并在配置文件中添加了一个部分,如上面的原始问题所示。对 inti = Membership.MinRequiredPasswordLength
的调用将定向到您的实现。这可能看起来像这样:MSDN 在此处提供了一个完整的示例。该示例向您展示如何读取配置文件以设置本地属性,例如
_minRequiredPasswordLength
。If you have overridden the
System.Web.Security.MembershipProvider
in your own class you can get the web.config membership settings as Robban suggests, just by calling theSystem.Web.Security.Membership
methods. However, these calls will be directed to your membership provider class, so you will need to provide some implementation.Supposing you have overridden the
MembershipProvider
class and added a section in the config file, as in the original question above. A call to inti = Membership.MinRequiredPasswordLength
will be directed to YOUR implementation. This might look like this:MSDN gives a complete example here. The example shows you how to read the config file to set the local properties like
_minRequiredPasswordLength
.