【问题标题】:ServiceStack AuthFeature null reference exceptionServiceStack AuthFeature 空引用异常
【发布时间】:2016-02-15 21:22:42
【问题描述】:

我有一个简单的 servicestack 自托管应用程序,除此之外,它还尝试使用身份验证。在 AppHost 构造函数中我拨打电话

                Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                new IAuthProvider[]
                {
                    new RoomsAuthProvider(),
                }));

但我在那个调用期间总是得到空引用异常。我试过分离调用-在一个字符串中创建身份验证功能,添加另一个-AuthFeature 创建失败。我也试过打电话

                Container.Register(new MemoryCacheClient());

这没有任何改变。欢迎任何想法。附上 Stacktrace

ServiceStack.AuthFeature.<.ctor>b__a(String s)
ServiceStack.AuthFeature..ctor(Func`1 sessionFactory, IAuthProvider[] authProviders, String htmlRedirect)
CoreServer.Program.AppHost..ctor() в C:\Users\Sorrow\documents\visual studio 2015\Projects\RoomsServicestack\CoreServer\Program.cs
CoreServer.Program.Main(String[] args) в C:\Users\Sorrow\documents\visual studio 2015\Projects\RoomsServicestack\CoreServer\Program
System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()

【问题讨论】:

    标签: c# .net servicestack httpserver


    【解决方案1】:

    在 AppHost 构造函数中我进行调用

    不要在 AppHost 构造函数中注册任何插件,所有配置都应该在 AppHost.Configure() 内进行,例如:

    public override void Configure(Container container)
    {
        Plugins.Add(new AuthFeature(() => new AuthUserSession(),
            new IAuthProvider[] {
                new RoomsAuthProvider(),
            }));
    }
    

    这和你的问题无关,但是如果你想注册一个Caching Provider你需要注册ICacheClient接口,例如:

    Container.Register<ICacheClient>(new MemoryCacheClient());
    

    这将让您通过ICacheClient 接口解决依赖关系:

    var cache = Container.Resolve<ICacheClient>();
    

    这是必需的,因为任何使用缓存的内置服务都会解析注册的 ICacheClient 依赖项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2011-05-16
      • 2013-01-19
      • 2023-03-27
      • 2012-10-20
      • 2013-09-21
      相关资源
      最近更新 更多