【发布时间】:2013-11-06 14:02:35
【问题描述】:
我需要访问控制器之外的 AuthenticationManager 的有效实例。例如,在自定义 AuthroizeAttribute 中。在用于创建使用 ASP.NET Identity 的 MVC 5 应用程序的模板中,它在 AccountController 中创建此代码以创建 AuthenticationManager 的实例。
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
这个HttpContext是Controller的一个属性。如果我不在控制器中,如何创建具有正确上下文的 AuthenticationManager?
我很难找到任何关于 ASP.NET Identity 和 OWIN 的好的文档。
【问题讨论】:
-
不能用 System.Web.HttpContext.Current 获取当前的 HttpContext 吗?
-
那行得通。谢谢。如果你想把它作为答案,我会接受。
标签: c# asp.net-mvc security asp.net-mvc-5 asp.net-identity