【问题标题】:Where is the sessions hash in the Chrome Dev Tools?Chrome 开发工具中的会话哈希在哪里?
【发布时间】:2016-12-02 16:36:26
【问题描述】:

我在会话哈希中存储了一个计数器,每次我在Store 控制器中调用index 操作时,该计数器都会递增。

我在Store 视图中打印出来,如代码和屏幕截图所示。

我知道我可以通过删除 cookie 来“重置计数器”,如屏幕截图所示。而且我知道我在服务器上打印会话哈希。但是如何在 chrome 开发工具中查看会话哈希?

store_controller.rb

class StoreController < ApplicationController
  def index
    @products = Product.order(:title)
    session[:counter] ||= 0
    session[:counter] += 1
  end
end

存储/index.html.erb

<p id="notice"><%= notice %></p>

<h1>Your Pragmatic Catalog</h1>
<p><%= session[:counter] %></p>
<% p session %>

<% cache @products do %>
  <% @products.each do |product| %>
    <% cache product do %>
      <div class="entry">
        <%= image_tag(product.image_url) %>
        <h3><%= product.title %></h3>
        <%= sanitize(product.description) %>
        <div class="price_line">
          <span class="price"><%= number_to_currency(product.price) %></span>
          <%= button_to 'Add to Cart', line_items_path(product_id: product) %>
        </div>
      </div>
    <% end %>
  <% end %>
<% end %>

截图

【问题讨论】:

  • 您使用什么会话存储策略?在任何情况下,不要期望能够从浏览器访问会话内容,内容并不总是在浏览器中,如果存在,它们将被加密以防止人们查看或更改东西。
  • 不确定,我使用的是默认的 rails 5 策略。我读了a blog post,发现了这个rails guide,这似乎是对自己进行更多教育的好读物:)我认为会话存储在浏览器中,看起来它只是存储的cookie,所以它更复杂比我原先想象的要好
  • 有时 cookie 是整个会话,有时它只是一个引用存储在服务器端的东西的 ID。在任何一种情况下,cookie 都会被加密以防止篡改。

标签: ruby-on-rails session cookies web google-chrome-devtools


【解决方案1】:

如 Hartl 的 Rails Tutorial 中所述,会话哈希已加密,因此您无法从浏览器中以纯文本形式查看它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 2016-03-20
    • 1970-01-01
    • 2013-12-08
    • 2017-12-03
    • 2017-05-17
    • 2018-09-29
    相关资源
    最近更新 更多