相关疑难解决方法(0)

MVC 5 IoC和身份验证

我即将开始一个项目,我将使用MVC5.但是,由于我想使用IoC并稍后重用我的用户表,并向其添加自定义内容,我发现很难看到我如何使用MVC5附带的新Identity框架.

我越来越关注基本形式的认证.你有什么解决方案?

我的需求:

  • 必须注入用户存储库/服务
  • 用户存储库必须驻留在DAL中
  • 用户存储库必须能够支持除EF之外的其他技术
  • 使用OpenID和OAuth进行身份验证必须要轻松实现
  • 必须安全
  • 应该可以在其他项目中重复使用,例如.WPF

我一直在寻找答案,但我看到的一切都是在控制器中硬编码的.

你是怎么解决的?您是从头开始编写的,还是可以绑定到可以扩展到其他.NET平台的东西,如WCF和WPF?

以下代码直接来自默认ASP.NET MVC 5模板中的AccountController.它做的第一件事是Bastard Injection.

[Authorize]
public class AccountController : Controller
{
    public AccountController()
        : this(
            new UserManager<ApplicationUser>(
                new UserStore<ApplicationUser>(
                    new ApplicationDbContext())))
    {
    }

    public AccountController(UserManager<ApplicationUser> userManager)
    {
        UserManager = userManager;
    }
}
Run Code Online (Sandbox Code Playgroud)

接受的答案将交给那个人,它向我展示了他们所做的事情,其中​​包含了上述要求

c# authentication asp.net-mvc entity-framework dependency-injection

16
推荐指数
2
解决办法
1万
查看次数