加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ServiceStack Session在MVC Controller中始终为n

发布时间:2020-12-16 09:52:53 所属栏目:asp.Net 来源:网络整理
导读:我正在使用服务堆栈MVC powerpack创建一个ASP.NET MVC 4应用程序,利用服务堆栈的auth和会话提供程序.我正在从社交bootstrap API项目中复制许多逻辑.我的控制器继承自以下基本控制器: public class ControllerBase : ServiceStackControllerCustomUserSessio
我正在使用服务堆栈MVC powerpack创建一个ASP.NET MVC 4应用程序,利用服务堆栈的auth和会话提供程序.我正在从社交bootstrap API项目中复制许多逻辑.我的控制器继承自以下基本控制器:

public class ControllerBase : ServiceStackController<CustomUserSession>

实现方式如下:

public class ControllerBase : ServiceStackController<CustomUserSession> {}

CustomUserSession继承自AuthUserSession:

public class CustomUserSession : AuthUserSession

登录后,我的CustomUserSession OnAuthenticated()方法运行,但是当我重定向回我的控制器时,没有填充UserSession,例如

public override void OnAuthenticated(IServiceBase authService,IAuthSession session,IOAuthTokens tokens,Dictionary<string,string> authInfo)
{
    base.OnAuthenticated(authService,session,tokens,authInfo);
    CustomFoo = "SOMETHING CUSTOM";

    // More stuff
}

public class MyController : ControllerBase
{
    public ActionResult Index()
    {
        // After having authenticated
        var isAuth = base.UserSession.IsAuthenticated; // This is always false
        var myCustomFoo = base.UserSession.CustomFoo; // This is always null

    }
}

谁能看到我在这里失踪的东西?

解决方法

请参阅ServiceStack Google Group – https://groups.google.com/forum/?fromgroups=#!topic/servicestack/5JGjCudURFU中的问题

在使用MVC内的JsonSeviceClient(或任何serviceClient)进行身份验证时,cookie不会与MVC请求/响应共享.

在MVC Controller中对ServiceStack进行身份验证时,应将MVC HttpContext发送到ServiceStack.像下面的东西应该工作……

var authService = AppHostBase.Resolve<AuthService>();
authService.RequestContext = System.Web.HttpContext.Current.ToRequestContext();
var response = authService.Authenticate(new Auth
{
  UserName = model.UserName,Password = model.Password,RememberMe = model.RememberMe
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读