- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的一个项目中使用 ServiceStack 作为基础库。我将我的应用程序分为两部分:API 和 WEB 应用程序,它们是单独的项目和存储库。
身份验证应该在 API 层上进行,并且应该缓存在那里。我在 API Server 中使用 Ormlite 缓存客户端。
在 API AppHost.cs 中
var dbFactory = new OrmLiteConnectionFactory("ConnectionString",SqlServerDialect.Provider);
container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
container.Resolve<ICacheClient>().InitSchema();
Plugins.Add(new AuthFeature(() => new APISession(),
new IAuthProvider[] {
new APICredentialsAuthProvider(new AppSettings())
}));
在APICredentialsAuthProvider中,我正在保存 session ,该 session 存储在CacheEntry
表中的Db中
我使用 apiurl/auth
通过 ajax 调用在 Web 应用程序中对用户进行身份验证,该调用返回带有 sessionId
的 AuthenticateResponse
。
我将此 sessionId 更新为 cookie 作为 s-id
,然后根据在 ss-id
或 ss- 中更新的请求类型在预请求过滤器中更新pid
.
//Inside Web application apphost
this.PreRequestFilters.Add((req, res) =>
{
System.Net.Cookie cookie = req.Cookies["s-id"];
req.Cookies["ss-id"] = cookie;
req.SetSessionId(cookie.Value)
});
此方法不会从缓存(在我的例子中为 Ormlite)以及 Web 和 Api 应用程序中提供的相应配置中获取 session 。
实现这一目标的最佳方法是什么?
但是我可以使用缓存客户端访问 session
//Inside Web application apphost
this.PreRequestFilters.Add((req, res) =>
{
System.Net.Cookie cookie = req.Cookies["s-id"];
req.Cookies["ss-id"] = cookie;
req.SetSessionId(cookie.Value);
APISession cachedSession = GetCacheClient(req).Get<APISession(SessionFeature.GetSessionKey(cookie.Value));
WEBSession session.PopulateWith<WEBSession, APISession>(cachedSession);
});
这工作正常,我能够获取 session ,但是通过将其放入预请求过滤器中,会增加来 self 的 Web 应用程序的数据库调用(在每个请求上)。
是否有任何替代解决方案可以实现相同的目的?
提前致谢!!
最佳答案
如果您在同一域后面对多个 Web 应用程序进行负载平衡,则使用 distributed Caching Providers 中的任何一个就像 OrmLiteCacheClient
将在向任一应用程序发出请求时发送 ServiceStack 的 ss-id/ss-pid
Cookie:
http://example.org/app1 -> http://internal:8001/
/app2 -> http://internal:8002/
/app3 -> http://internal:8003/
然后,只要每个应用程序配置了相同的 OrmLiteCacheClient
,在一个应用程序中创建的 session 将在所有 3 个应用程序中可见。
您可以通过在 IRequest.Items
上设置它来阻止进一步的数据库访问以检索该请求的 session ,例如:
req.Items[Keywords.Session] = session;
然后,对该请求的 session 的任何访问都将从 IRequest
项字典中解析,而不是访问数据库。
另一个可供您在所有 3 个应用程序中进行身份验证的替代身份验证解决方案是使用无状态 JWT Auth Provider .
关于session - 负载平衡环境中的 ServiceStack session 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831553/
我正在尝试了解二叉树的属性。但我不确定一件事: 定义。二叉树的声明: 如果对于每个节点,它认为左子树中的内部节点数和右子树中的内部节点数最多相差 1,则二叉树是平衡的。 如果任意两个叶子的差异都存在,
我有一个带有分片键和索引的集合。但是当我运行平衡时,不会为这个集合移动 block ,因为其他集合 block 正在按预期移动到其他机器。此集合中仅移动了一个 block 。 最佳答案 目前(这将在不
给定一个data.table如下,id1是一个subject-level ID,id2是一个within-subject repeated-measure ID,X 是数据变量,其中有很多。我想平衡数
由于 C++ 集合是在二叉树中实现的,如果我们以递增或递减顺序插入项目,那么集合将更像是一个列表而不是树。有没有什么方法可以在插入项目后平衡树? 最佳答案 C++ 集(即 std::set)通常实现为
我是一名初学者程序员,设计了一个智能手机网站,我有一个主体背景图像,我想慢慢改变颜色平衡,交替颜色,就像有人将 Photoshop 颜色平衡控制条调整一定百分比一样。任一方向。当您查看页面时,这种情况
我开发了一段多线程代码。该代码在 Web 应用程序中调用,因此可能由多个线程(请求)并行调用。为了控制此代码将要创建的线程数量(通过多个并行请求调用),我使用静态共享 ThreadPoolExecut
我正在为 Linux 内核开发一些网络驱动程序。我有几个 if-else 条件,我正在重新分配或释放“skb”结构——这是我有点困惑的地方。关于我在那些 if-else 中做什么 - 我遇到了 2 种
平衡 BST 的最佳和最差搜索性能是什么?每种情况发生时如何用一句话解释? 最佳答案 最佳情况:当搜索到的元素位于树的根部时。你得到 O(1)。 最坏情况:当搜索元素在最长分支的叶子处时,树是单边的。
我在平衡 AVL 树问题上遇到了麻烦,因为我的解决方案似乎与教科书后面的解决方案冲突。我查看了 AVL 树的在线可视化,他们认为我的是正确的。我的课本错了吗? 这是树: 然后我必须将 65 插入到这个
我有一个系统,我在其中使用 RS232 来控制一个灯,该灯接受以浮点形式给出的表示电压(在 2.5 - 7.5 范围内)的输入。然后控件会给出 0 到 6000 范围内的输出,这是传感器拾取的亮度。
我有一个分层目录,每个目录中有很多文件,每个文本文件中有很多 URL 字符串。我想下载 Hadoop 中所有文件中的所有 URL,以实现更好的平衡。 例如,如果我有 1+5 个节点的 Hadoop 集
请查看附件图片,这是一种跷跷板。但从图像来看,黑体具有相同的密度。并且水平矩形使用“Revolute”关节与三角形相连。但仍然没有任何建议。在目前的情况下,它需要平衡。 最佳答案 由于浮点精度等限制导
因此,在平衡 KD 树时,您应该找到中位数,然后将所有较小的元素放在左子树上,将较大的元素放在右子树上。但是,如果您有多个元素与中位数具有相同的值,会发生什么情况?他们进入左子树,右子树还是丢弃它们?
请帮我找到一种干净的方法来从现有数组中创建一个新数组。如果任何类的示例数小于该类中的最大示例数,则应该进行过采样。样本应该从原始数组中提取(随机或顺序都没有区别) 比方说,初始数组是这样的: [ 2
我是一名软件开发人员,但想成为服务器可扩展性领域的新架构师。 在多个服务使用同一数据集的情况下,旨在扩展冗余和负载平衡。 问题是:在一个理想主义的系统中,服务是否应该尝试优化它们的内部处理以减少对远程
假设我有 10 个分区用于 Kafka 中的给定主题。 我的选择是在消费者之间自动平衡这 10 个分区的负载? 我已经阅读了这篇文章 https://stackoverflow.com/a/28580
假设我有一个 B 树,其节点为 3-4 配置(3 个元素和 4 个指针)。假设我按照规则合法地建立我的树,我是否有可能达到一层中有两个节点并且一个节点有 4 个退出指针而另一个节点只有两个退出指针的情
当光标在一个括号上时,如何跳转到配对括号。很高兴在 工作emacs -nw . 就像 % 在 Vim 中。 ;;从@Lindy、@Francesco 得到提示后,我发现了更多: C-M-f
我在平衡 AVL 树时遇到问题。我一直在寻找如何平衡它们的步骤,但我找不到任何有用的东西。 我知道有4种: 单左旋 单右旋 双左右旋转 双左右旋转 但我就是无法得到如何选择其中之一和 在哪个节点上应用
我想获得类似于打印中平衡文本行但用于 block 元素的结果。假设在一个 300/100 像素的容器中有一组 50/50 像素的盒子。在容器中 float 盒子将使它们填满一“行”,然后像这样包裹到下
我是一名优秀的程序员,十分优秀!