我即将开始一个项目,我将使用MVC5.但是,由于我想使用IoC并稍后重用我的用户表,并向其添加自定义内容,我发现很难看到我如何使用MVC5附带的新Identity框架.
我越来越关注基本形式的认证.你有什么解决方案?
我的需求:
我一直在寻找答案,但我看到的一切都是在控制器中硬编码的.
你是怎么解决的?您是从头开始编写的,还是可以绑定到可以扩展到其他.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