gpt4 book ai didi

asp.net - 如何从 web.config 中获取 maxInvalidPasswordAttempts?

转载 作者:行者123 更新时间:2023-12-01 02:59:42 25 4
gpt4 key购买 nike

我需要重写很多 asp.net 成员(member)资料,因为它不能满足我的需求。所以在我的自定义验证方法中,如果失败,我会检查他们的密码。我捕获了aspnet_membership
maxInvalidPasswordAttempts 列并将其加 1。

所以在我的 web.config 中我将它设置为 10。所以我想从 web.config 中获取值并与用户拥有的值进行比较。我怎样才能做到这一点?

另外我想当我在 if 语句中进行比较时,我会将用户锁定吗?

最佳答案

您应该在提供程序的 Initialize 方法中从 web.config 获取配置值,如下所示:

public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
throw new ArgumentNullException("config");

// Initialize the abstract base class.
base.Initialize(name, config);

pApplicationName = GetConfigValue(config["applicationName"],
System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
pMaxInvalidPasswordAttempts = Convert.ToInt32(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"));
// ...

在您的应用程序中,您可以将其引用为 Membership.MaxInvalidPasswordAttmpts。

有一个 full implementation of a custom MembershipProvider on MSDN .以此为例,我能够在几个小时内实现一个提供程序。

关于asp.net - 如何从 web.config 中获取 maxInvalidPasswordAttempts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1296108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com