2012-09-04 51 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自動裝配,也許上面會解決得

相關問題