我在试着让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中获取当前用户会话?
发布于 2014-08-22 20:58:25
我也有一个空的UserSession,通过在AppHost的Configure方法中添加以下代码来解决它:
//Set MVC to use the same Funq IOC as ServiceStack
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();不确定AuthService自动装配,也许上面的方法也能解决这个问题
https://stackoverflow.com/questions/12268411
复制相似问题