代码之家  ›  专栏  ›  技术社区  ›  Orsi

我无法引用Microsoft。奥温。安全AuthenticationManager,为什么?

  •  1
  • Orsi  · 技术社区  · 7 年前

    我的页面上出现以下错误:

    Server Error in '/' Application.
    
    The current type, Microsoft.Owin.Security.IAuthenticationManager, is an interface and cannot be constructed. Are you missing a type mapping? 
    

    我发现我应该把这个代码放进去 Unityconfig.cs 要解决此问题,请执行以下操作:

    container.RegisterType<IAuthenticationManager>(
                new InjectionFactory(
                    o => System.Web.HttpContext.Current.GetOwinContext().Authentication
                )
            );
    

    但问题是IAuthenticationManager不可见 enter image description here

    虽然我添加了 Owin.Security 作为参考,我有

    using Microsoft.Owin.Security;
    

    你能给我一些提示吗?

    1 回复  |  直到 7 年前
        1
  •  4
  •   DavidG    7 年前

    请注意,您尝试使用的界面( Microsoft.Owin.Security.IAuthenticationManager )不在 Microsoft.Owin.Security.dll 但实际上 Microsoft.Owin.dll . 检查顶部告诉您名称空间和程序集的两行。所以您只需要添加对该程序集的引用。

    对于这样的情况,总是值得检查文档,因为名称空间并不总是等同于程序集名称。