【问题标题】:How to create a valid AuthenticationManager without a controller?如何在没有控制器的情况下创建有效的 AuthenticationManager?
【发布时间】: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


【解决方案1】:

你不能用 System.Web.HttpContext.Current 获取当前的 HttpContext 吗? ——

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 2013-09-26
    • 2021-01-12
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多