3

I've followed the samples in SocialBootstrapAPi for ServiceStack but I don't get it how the redirects are wired up. When I go to the Secured controller being unauthenticated I get redirected back to the index page. I was unable to replicate the behaviour in my own application. Did not find where this wirings are done - can't find them in SocialBootstrapApi's web.config?

I've inherited from the ServiceStackController<AuthUserSession> and put [Authenticate] on my base controller. This is the error I get:

[NullReferenceException: Object reference not set to an instance of an object.]
   ServiceStack.ServiceInterface.SessionExtensions.SessionAs(ICacheClient cache, IHttpRequest httpReq, IHttpResponse httpRes) +90
   ServiceStack.Mvc.ServiceStackController.SessionAs() +64
   ServiceStack.Mvc.ServiceStackController`1.get_UserSession() +36
   ServiceStack.Mvc.ServiceStackController`1.get_AuthSession() +5
   ServiceStack.Mvc.ExecuteServiceStackFiltersAttribute.OnActionExecuting(ActionExecutingContext filterContext) +97

This is what I have in the AppHost.cs file:

        //Enable Authentication
        ConfigureAuth(container);

        //Register In-Memory Cache provider. 
        //For Distributed Cache Providers Use: PooledRedisClientManager, BasicRedisClientManager or see: https://github.com/ServiceStack/ServiceStack/wiki/Caching
        container.Register<ICacheClient>(new MemoryCacheClient());
        container.Register<ISessionFactory>(c => 
            new SessionFactory(c.Resolve<ICacheClient>()));

ConfigureAuth() is similar to the SocialBootstrapApi sample (not exactly the same but close) - I don't think there's something missing here.

So how does this work?

mare
  • 13,033
  • 24
  • 102
  • 191
  • Did you set your IoC for your MVC controller? `ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));` ? – Eli Gassert Dec 10 '12 at 21:35
  • Thanks I removed this line when first started to modify the default AppHost, now I've reintroduced it and it works. You can post this as the answer. – mare Dec 11 '12 at 10:18
  • So the answer is actually two part, fixing the session and using CustomAuthenticationMvc project for reference on how to implement redirections. – mare Dec 11 '12 at 10:20
  • ok, promoted to an answer. Of course you can accept Mythz answer if it's more on-topic for what you want. – Eli Gassert Dec 11 '12 at 21:20

2 Answers2

4

Promoting comment to an answer, per OPs request:

Did you set your IoC for your MVC controller? ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));

Eli Gassert
  • 9,745
  • 3
  • 30
  • 39
2

Look at this question to see how to change the HtmlRedirect used by ServiceStack's Authentication.

You may also find the CustomAuthenticationMvc project in ServiceStack UseCases more useful since it only focuses on Authentication in MVC.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390