如何使用自定义MembershipProvider

本文关键字:MembershipProvider 自定义 何使用 | 更新日期: 2023-09-27 18:00:16

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

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

据我所知,我将其添加到根级别的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>

这是我的课:

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]的控制器方法时,没有任何记录。我是不是错过了什么?

如何使用自定义MembershipProvider

defaultProvider属性更改为您的会员资格提供商:

<membership defaultProvider="MyMembershipProvider">

将ASP.NET应用程序配置为使用成员身份

相关文章:
  • 没有找到相关文章