我正在尝试使用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]的控制器方法时。我错过了什么吗?
答案 0 :(得分:2)
将defaultProvider
属性更改为您的会员提供者:
<membership defaultProvider="MyMembershipProvider">