首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在baseController中获取UserSession?

如何在baseController中获取UserSession?
EN

Stack Overflow用户
提问于 2012-09-05 01:20:31
回答 1查看 147关注 0票数 1

我在试着让UserSession。

代码语言:javascript
复制
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中获取当前用户会话?

EN

回答 1

Stack Overflow用户

发布于 2014-08-22 20:58:25

我也有一个空的UserSession,通过在AppHost的Configure方法中添加以下代码来解决它:

代码语言:javascript
复制
    //Set MVC to use the same Funq IOC as ServiceStack
    ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
    ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();

不确定AuthService自动装配,也许上面的方法也能解决这个问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12268411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档