【问题标题】:Sinatra session is lost during post on Internet Explorer在 Internet Explorer 上发布期间 Sinatra 会话丢失
【发布时间】:2012-08-26 14:21:46
【问题描述】:

当我发帖时,其中一个会话变量在 IE 中丢失了。

这个 web 应用在 Chrome 和 Firefox 中完美运行。

这是错误:

NoMethodError at / 

undefined method `include?' for nil:NilClass
file: welcometo.rb
location: xml_file_to_use 
line: 19

报错的方法如下:

def xml_file_to_use
   groups = allowed_groups
   #Which xml file should I write to
   if (session[:location_group].include? allowed_groups[0] ) <----Line 19
    ......
end

这是一个解释和我的代码:

当用户登录时,会话变量被设置:

#Check to see if the user is authorized
auth_token = Adauth.authenticate(params[:user], params[:password])
if auth_token 
    session[:user] = params[:user]
    session[:first_name] = auth_token.first_name.tr('/"[]', '') 
    session[:location_group] = (auth_token.groups & allowed_groups)
    redirect '/'
else 
    redirect '/login'
end

接下来我根据这些会话值设置变量:

get '/' do
  if session["user"] != nil
     @first_name = session[:first_name]
     @groups = session[:groups]
     @xml_file = xml_file_to_use 
     @location = location
     erb :form
  else 
    redirect '/login'
  end

end

这部分工作得很好。我可以说出来,因为我在视图中使用了@location 变量。

这里是定位方法:

#Setup Location Variable
def location
  if (session[:location_group].include? allowed_groups[0] ) <-- This same code errors during a post in IE
     return 'Eagan'
   else
     return 'Chicago'
   end  
end

【问题讨论】:

标签: ruby internet-explorer session sinatra


【解决方案1】:

Konstantin Haase 是正确的,这一定是一个错误。

从他发布的链接中,我发现将它放在我的welcome.rb 文件的顶部可以解决问题:

set :protection, except: :session_hijacking

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2023-04-04
    • 2011-02-26
    相关资源
    最近更新 更多