ServiceStack Authenticate属性导致null ref异常 - pull请求267

时间:2012-09-26 04:40:20

标签: authentication servicestack

我正在使用ServiceStacks身份验证机制创建一个MVC3站点。当我将AuthenticateAttribute添加到控制器时,我得到一个空引用异常:

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=ServiceStack.FluentValidation.Mvc3
StackTrace:
at ServiceStack.Mvc.ExecuteServiceStackFiltersAttribute.OnActionExecuting(ActionExecutingContext  filterContext) in  C:\src\ServiceStack\src\ServiceStack.FluentValidation.Mvc3\Mvc\ExecuteServiceStackFiltersAttribute.cs:line 21
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

我可以在github中看到拉请求#267似乎使得一些空的引用确切检查我的代码当前抛出的位置。我有另一个认证工作的项目,但新的失败代码在较新版本的ServiceStack上运行,我看不出有什么区别,所以任何关于什么可能导致新版本的服务堆栈的异常的想法(v。 3.9.18)

这是我的配置代码:

Plugins.Add(new AuthFeature(
                        () => new AuthUserSession(), // Here a custom IAuthSession implementation could be used instead of UserSession.
                        // Allow authentication by using cookies set when authenticating with username/password credentials posted to the /auth/credentials service.
                        new IAuthProvider[]{ new CredentialsAuthProvider() }
                        )
            );
 //Enable Funq IOC in MVC controllers.
 ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));


IUserAuthRepository userRepository = new OrmLiteAuthRepository(dbFactory);
container.Register(userRepository);
container.Register<ICacheClient>(new MemoryCacheClient());

        // Initialise Registration feature, providing the /register route.
        Plugins.Add(new RegistrationFeature());

我的Controller基类:

public abstract class ControllerBase : ServiceStackController<AuthUserSession> {
    public IDbConnectionFactory Db { get; set; }
    public ILog Log { get; set; }
    //Common extension point for all controllers. Inherits from ServiceStack to take advantage of SS powerpack + auth.
    public override string LoginRedirectUrl {
        get {
            return "/Auth/Login?redirect={0}";
        }
    }

}

1 个答案:

答案 0 :(得分:1)

我已经更新了解决(v3.9.18 +)中的空引用异常的ServiceStack.Mvc NuGet包。尝试更新,看看是否能解决它。