【问题标题】:Session without authentication with MemoryCacheClient in servicestack with MVC4使用 MVC4 在服务堆栈中使用 MemoryCacheClient 进行身份验证的会话
【发布时间】:2015-07-09 11:13:45
【问题描述】:

我是 Servicestack 的新手。我将 MVC4 应用程序和 servicestack 应用程序部署在不同的服务器上。 我想在没有 MemoryCacheClient 身份验证的情况下使用 servicestack 会话。

我无法理解

中给出的解释

https://github.com/ServiceStack/ServiceStack/wiki/Sessions

我想检查每个请求是否存在会话,如果 seesion 为空,则使用自定义值作为用户 ID 创建新会话。

我的配置方法如下

public override void Configure(Container container)
        {
            //use session feature only

            Plugins.Add(new SessionFeature());

             // use MemoryCacheClient 

            container.Register<ICacheClient>(new MemoryCacheClient()); 

            // in global request filter check if session exists
            this.GlobalRequestFilters.Add((req, res, requestDto) =>
            {  
                //check if session exists 
                var sessionId = req.GetSessionId();
                if (sessionId == null)
                {
                    //if no populate session with user defined data ( user id from requestDto)
                }
                else
                { 
                   //how to get the values from session ?
                }
    }

请帮忙。 提前致谢

【问题讨论】:

    标签: asp.net-mvc web-services rest servicestack


    【解决方案1】:

    SessionFeature 已经注册了自己的全局请求过滤器,以自动创建缺少的临时或永久会话 ID(即 ss-idss-pid)。

    听起来你想注册一个Custom AuthEvent 来响应会话生命周期中的不同事件,即IAuthEvents.OnCreated()

    【讨论】:

    • 谢谢。还有一个问题如何在 servicestack 中验证网络服务凭证
    • @amol register AspNetWindowsAuthProvider in AuthFeature on Server 和 ServiceClients 可以使用client. Credentials = CredentialCache.DefaultCredentials
    • 我添加了 Plugins.Add(new AuthFeature( () => new CustomUserSession(), new IAuthProvider[] { new AspNetWindowsAuthProvider(this) { AllowAllWindowsAuthUsers = true }, } ));在 apphost 和客户端我使用 var client = new JsonServiceClient(ConfigurationManager.AppSettings["applicationUrl"]) { Credentials = CredentialCache.DefaultCredentials };
    • 要使用网络凭据,我可以使用 var client = new JsonServiceClient(ConfigurationManager.AppSettings["applicationUrl"]) { //network authentication Credentials = new NetworkCredential(user, pwd, domain) };并在 servicestack 上使用自定义身份验证?
    • @amol 当然,它只是传递给发出 HTTP 请求的底层 HttpWebRequest,所以它支持它支持的任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2015-05-18
    相关资源
    最近更新 更多