gpt4 book ai didi

c# - 如何使用自定义 MembershipProvider?

转载 作者:太空宇宙 更新时间:2023-11-03 11:08:18 25 4
gpt4 key购买 nike

我正在尝试使用带有 ASP MVC 的自定义 MembershipProvider 来保护我的应用程序中的 Controller 。

只是为了了解一些背景知识,我最终将使用网络服务来验证每个用户。

据我了解,我将其添加到根级别的 web.config 中,如下所示:

<authentication mode="Forms">
<forms loginUrl="~/Login/Login" timeout="2880" />
</authentication>
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider" type="DANet.security.MyMembershipProvider" />
</providers>
</membership>

这是我的类(class):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace DANet.security
{
public class MyMembershipProvider : MembershipProvider
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public override bool ValidateUser(string username, string password)
{
log.Debug("MyMembershipProvider");

throw new NotImplementedException();
}

public override MembershipUser CreateUser(string username,
string password, string email, string passwordQuestion,
string passwordAnswer, bool isApproved,
object providerUserKey, out MembershipCreateStatus status)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override string ApplicationName
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override bool EnablePasswordReset
{
get { throw new NotImplementedException(); }
}

public override bool EnablePasswordRetrieval
{
get { throw new NotImplementedException(); }
}

public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override int GetNumberOfUsersOnline()
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override string GetPassword(string username, string answer)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override MembershipUser GetUser(string username, bool userIsOnline)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override string GetUserNameByEmail(string email)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override int MaxInvalidPasswordAttempts
{
get { throw new NotImplementedException(); }
}

public override int MinRequiredNonAlphanumericCharacters
{
get { throw new NotImplementedException(); }
}

public override int MinRequiredPasswordLength
{
get { throw new NotImplementedException(); }
}

public override int PasswordAttemptWindow
{
get { throw new NotImplementedException(); }
}

public override MembershipPasswordFormat PasswordFormat
{
get { throw new NotImplementedException(); }
}

public override string PasswordStrengthRegularExpression
{
get { throw new NotImplementedException(); }
}

public override bool RequiresQuestionAndAnswer
{
get { throw new NotImplementedException(); }
}

public override bool RequiresUniqueEmail
{
get { throw new NotImplementedException(); }
}

public override string ResetPassword(string username, string answer)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override bool UnlockUser(string userName)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}

public override void UpdateUser(MembershipUser user)
{
log.Debug("MyMembershipProvider");
throw new NotImplementedException();
}
}
}

我只是想看看这个类是否被 NET 使用并被调用。如您所见,我在每个方法中都有日志语句,当我登录时或当我尝试点击标记为 [Authorize] 的 Controller 方法时,没有任何记录。我错过了什么吗?

最佳答案

defaultProvider 属性更改为您的成员(member)提供者:

<membership defaultProvider="MyMembershipProvider">

Configuring an ASP.NET Application to Use Membership

关于c# - 如何使用自定义 MembershipProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14969235/

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