加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – MVC 3中的身份验证:滚动的方式

发布时间:2020-12-15 17:16:14 所属栏目:百科 来源:网络整理
导读:我编写了一组接口和相关的clases来使用Entity Framework对用户进行身份验证,而不是使用内置且相当过时的ASP.NET成员资格提供程序提供的sotred过程. 使用我的MVC 3应用程序实现AuthenticationService的最佳方法是什么? 我应该编写自定义提供程序并覆盖成员资
我编写了一组接口和相关的clases来使用Entity Framework对用户进行身份验证,而不是使用内置且相当过时的ASP.NET成员资格提供程序提供的sotred过程.

使用我的MVC 3应用程序实现AuthenticationService的最佳方法是什么?
我应该编写自定义提供程序并覆盖成员资格提供程序吗这看起来很简单但我并不真正关心微软给我们的工厂模型提供商工厂.

思考?

解决方法

我根据MVC 2附带的界面编写了自己的会员服务.由于我的应用程序中的授权比开箱即用的基于角色的东西复杂一点,我无法使用System.Web.Security.MembershipProvider .我仍然使用FormsAuthentication来跟踪登录用户.你失去了能够使用[Authorize(Roles =“Admin”)]和其他框架位,但就像我说我的应用程序不使用基于角色的身份验证.

public class MyMembershipService : IMembershipService
{
    private readonly IUserRepository userRepository;

    public MyMembershipService(IUserRepository userRepository)
    {
        this.userRepository = userRepository;
    }

    public virtual bool IsValid(string username,string password)
    {
        var user = userRepository.FindByUsername(username);

        return user != null && user.PasswordMatches(password);
    }

    public virtual bool AllowedToLogIn(string username)
    {
        var user = userRepository.FindByUsername(username) ?? new User();

        return user.AllowedToLogIn();
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读