2012-09-04 54 views
1

我想获得UserSession。如何在baseController中获取UserSession?

public abstract class BaseController : ServiceStackController<CustomUserSession> 
{ 
    public AuthService AuthService { get; set; } // NOT Autowired -Problem 1 
    public BaseController() 
    { 
     //this.ControllerContext = null -Problem 2 
     //UserSession 'UserSession' threw an exception of type System.NullReferenceException' -Problem 3 

     if (!this.ControllerContext.IsChildAction) 
     { 

     } 
    } 
} 

但有3个问题,你可以看到。 为什么我需要这个?我想在_Layout.cshtml中应用用户特定的CSS。

如何在Controller中获取当前用户会话?

回答

1

我有一个空UserSession藏汉,通过添加以下代码到配置方法APPHOST解决它:

//Set MVC to use the same Funq IOC as ServiceStack 
    ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container)); 
    ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>(); 

不能确定AuthService自动装配,也许上面会解决得

相关问题