我们的调查表明,并非所有浏览器都以统一的方式尊重HTTP缓存指令。

出于安全原因,我们不希望应用程序中的某些页面被web浏览器缓存。这必须至少适用于以下浏览器:

Internet Explorer 6+Firefox 1.5+Safari 3+歌剧9+铬

我们的要求来自安全测试。从我们的网站注销后,您可以按后退按钮并查看缓存的页面。


当前回答

这些指令不会减轻任何安全风险。它们实际上是为了迫使UA更新不稳定的信息,而不是阻止UA保留信息。看到这个类似的问题。至少,不能保证任何路由器、代理等也不会忽略缓存指令。

更积极的是,有关计算机物理访问、软件安装等方面的政策将使您在安全方面领先于大多数公司。如果这些信息的消费者是公众,你唯一能做的就是帮助他们明白,一旦信息到达他们的机器,那台机器就是他们的责任,而不是你的责任。

其他回答

我用这种方式解决了。

2个注意事项:

1) 服务器端事件不是在后退单击时触发的,而是javascript。

2) 我有两个javascript来读/写cookie

function setCookie(name, value, days)
{
    var expires = "";
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function getCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for (var i = ca.length - 1; i >= 0; i--)
    {
        var c = ca[i];
        while (c.charAt(0) == ' ')
        {
            c = c.substring(1, c.length);
        }

        if (c.indexOf(nameEQ) == 0)
        {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return null;
}

在我的Page_Load中,我插入了以下内容:(这不是在单击后启动的)

    protected void Page_Load(object sender, EventArgs e)
    {
       Page.RegisterClientScriptBlock("", "<script>setCookie('" + Session.SessionID + "', '" + Login + "', '100');</script>");
    }

其中“Login”是我的id值,注销后为-1(可以使用其他值,例如布尔值)。

然后在我的页面中添加了以下内容:(这是在单击后启动的)

<script type="text/javascript">
if (getCookie('<%= Session.SessionID %>') < 0)
        {
            if (history.length > 0)
            {
                history.go(+1);
            }
        }

</script>

没有别的。

使用此解决方案,仅在同一浏览器上的每个页面注销后,才在每个页面上启用反向单击。

//In .net MVC
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult FareListInfo(long id)
{
}

// In .net webform
<%@ OutputCache NoStore="true" Duration="0" VaryByParam="*" %>

经过一番研究,我们得出了以下标题列表,这些标题似乎涵盖了大多数浏览器:

有效期:1997年7月26日星期六05:00:00 GMT缓存控制:无缓存,私有,必须重新验证,最大失效=0,后检查=0,预检查=0无存储Pragma:无缓存

在ASP.NET中,我们使用以下代码段添加了这些代码:

Response.ClearHeaders(); 
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0 
Response.AppendHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.0 

从以下位置找到:http://forums.asp.net/t/1013531.aspx

如果您面临通过SSL和cache:MS Office文件的IE6-IE8下载问题,则可以在POST请求时使用cache:private、no store header和return file。它起作用了。

完成BalusC->答案如果您使用的是perl,则可以使用CGI添加HTTP标头。

使用Perl:

Use CGI;    
sub set_new_query() {
        binmode STDOUT, ":utf8";
        die if defined $query;
        $query = CGI->new();
        print $query->header(
                        -expires       => 'Sat, 26 Jul 1997 05:00:00 GMT',
                        -Pragma        => 'no-cache',
                        -Cache_Control => join(', ', qw(
                                            private
                                            no-cache
                                            no-store
                                            must-revalidate
                                            max-age=0
                                            pre-check=0
                                            post-check=0 
                                           ))
        );
    }

使用apachehttpd.conf

<FilesMatch "\.(html|htm|js|css|pl)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>

注意:当我尝试使用html META时,浏览器忽略了它们并缓存了页面。