在Web.Config中设置ServiceStack Cookie域会导致会话ID在每个请求上更改

 活的精彩的人2011_373 发布于 2023-01-15 14:40

根据ServiceStack - 域和子域的身份验证,我在httpCookies部分设置了cookie域,它实际上有效 - 它可以正确设置cookie的域.

但我注意到,一旦我将这一行添加到配置中,就会在每个请求上生成一个新的会话ID,无论用户是否已经过身份验证.

我的代码很简单,很简单.

我的应用主机代码:

public override void Configure(Funq.Container container)
{
        Plugins.Add(new AuthFeature(() => new CustomUserSession(),
            new IAuthProvider[] {        
                    new CustomCredentialsProvider(), 
                }));

        container.Register(c => new PooledRedisClientManager("10.211.55.2:6379"));
        container.Register(c => c.Resolve().GetCacheClient());

        var userRep = new InMemoryAuthRepository();
        container.Register(userRep);
}

我的自定义凭据提供者

public class CustomCredentialsProvider : CredentialsAuthProvider
{
    public override bool TryAuthenticate(ServiceStack.IServiceBase authService, string userName, string password)
    {
        return true;
    }

    public override void OnAuthenticated(ServiceStack.IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary authInfo)
    {
        session.UserAuthName = "test user";
        session.UserName = "test user";

        authService.SaveSession(session);
    } 
}

我的默认页面:

public partial class _Default : WebForms.App_Start.PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //get session information in every way possible
            var session = this.UserSession;

            var sessionKey = SessionFeature.GetSessionKey();

            var session2 = SessionFeature.GetOrCreateSession(this.Cache);

            var session3 = this.Cache.Get(sessionKey);        

        }

将发布上面的sessionKey,并在每个请求(预期)上保持不变.添加:


  

导致sessionKey在每个请求中都不同; 几乎像饼干即将到期.将域名更改为"test.com"或".test.com"似乎没有什么区别.我将127.0.0.1 localhost和127.0.0.1 test.com添加到我的Windows主机文件中以获得良好的衡量标准.

同样,即使在进行身份验证之后,注释掉httpCookies行和会话ID也保持不变.添加上述行会导致会话在每个请求上发生更改,无论是否进行身份验证.

正在设置Cookie,并在每个请求中使用新的会话ID进行设置.

我可能做错了什么,我会在哪里覆盖这种行为?任何帮助表示赞赏.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有