相关疑难解决方法(0)

使用<meta>标签关闭所有浏览器的缓存?

我读到,当您无法访问Web服务器的标头时,您可以使用以下命令关闭缓存:

<meta http-equiv="Cache-Control" content="no-store" />
Run Code Online (Sandbox Code Playgroud)

但我也读到这在某些版本的IE中不起作用.是否有任何<meta>标签可以关闭所有浏览器中的缓存?

html firefox internet-explorer caching asp.net-web-api

427
推荐指数
5
解决办法
76万
查看次数

nodejs服务器中没有缓存

我已经读过为了避免在nodejs中缓存,有必要使用:

"res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');"
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何使用它,因为当我在代码中放入该行时会出现错误.

我的功能(我认为我必须编程没有缓存)是:

function getFile(localPath, mimeType, res) {
        fs.readFile(localPath, function(err, contents) {
                if (!err) {
                    res.writeHead(200, {
                    "Content-Type": mimeType,
                    "Content-Length": contents.length,
                'Accept-Ranges': 'bytes',
                    });
                //res.header('Cache-Control', 'no-cache');
                    res.end(contents);
                } else {
                    res.writeHead(500);
                    res.end();
                }
        });

}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何在我的代码中没有缓存?谢谢

caching node.js

38
推荐指数
4
解决办法
6万
查看次数

Node.js和Express会话处理 - 后退按钮问题

我的Express应用程序中有一个禁区"/仪表板".我使用一个非常小的函数来限制访问:

app.get('/dashboard', loadUser, function(req, res){
  res.render('dashboard', {
    username: req.session.username
  });
});

function loadUser(req, res, next){
  if (req.session.auth) {
    next();
  } else {
    res.redirect('/login');
  }
};
Run Code Online (Sandbox Code Playgroud)

问题是当我通过调用注销用户时...

app.get('/logout', function(req, res){
  if (req.session) {
    req.session.auth = null;
    res.clearCookie('auth');
    req.session.destroy(function() {});
  }
  res.redirect('/login');
});
Run Code Online (Sandbox Code Playgroud)

...会话被杀死但是当我在浏览器中点击Back Button时,我从浏览器的缓存中获得了受限制的页面.这意味着'/ dashboard'上没有GET,也没有用户登录验证.

我尝试在元(Jade模板)中使用no-cache,但它仍然不起作用.

meta(http-equiv='Cache-Control', content='no-store, no-cache, must-revalidate')
meta(http-equiv='Pragma', content='no-cache')
meta(http-equiv='Expires', content='-1')
Run Code Online (Sandbox Code Playgroud)

任何人?

session node.js express

17
推荐指数
2
解决办法
2万
查看次数

用户退出后,如何防止浏览器的后退按钮访问受限信息?

我正在使用github上的这个例子来获取护照本地策略与mongoose/mongodb.我遇到的问题是,当用户注销时,他们仍然可以通过点击浏览器上的后退按钮来访问受限信息.我对node.js有点新意,但我想在执行ensureAuthenticated后退和前进按钮之前需要实现某种类型的钩子来调用函数 - 一直位于代码的最底部.在用户注销后,如何通过点击后退按钮来阻止用户访问受限信息?

var express = require('express')
  , passport = require('passport')
  , LocalStrategy = require('passport-local').Strategy
  , mongodb = require('mongodb')
  , mongoose = require('mongoose')
  , bcrypt = require('bcrypt')
  , SALT_WORK_FACTOR = 10;

mongoose.connect('localhost', 'test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback() {
  console.log('Connected to DB');
});

// User Schema
var userSchema = mongoose.Schema({
  username: { type: String, required: true, unique: true },
  email: { type: String, required: true, unique: true },
  password: { …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js express passport.js

6
推荐指数
1
解决办法
5329
查看次数