如何清除浏览器缓存中,当用户使用C#在asp.net中注销? [英] How to clear browser cache when user log off in asp.net using c#?

查看:460
本文介绍了如何清除浏览器缓存中,当用户使用C#在asp.net中注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在asp.net中新。在成员注销 上单击事件使用功能我的asp.net应用程序 ClearSession( ),但是问题出现了注销后如果单击后退按钮上的浏览器被转发到缓存的页面。如何清除浏览器缓存因此用户不能查看其个人资料,如果他没有登录

 保护无效ClearSession()
{
    FormsAuthentication.SignOut();
    Session.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ExpiresAbsolute = DateTime.UtcNow.AddDays(-1d);
    Response.Expires = -1500;
    Response.CacheControl =无缓存;
}


解决方案

我觉得你是几乎没有。你需要更多的HTML头,支持所有浏览器。据<一个href=\"http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers\">this文章SO 的这些都是在所有浏览器工作的:

 的Cache-Control:no-cache的,没有店面,必重新验证
编译:无缓存
过期:0

满code这个是:

  HttpContext.Current.Response.AddHeader(缓存控制,无缓存,无店铺,必重新验证);
HttpContext.Current.Response.AddHeader(杂注,无缓存);
HttpContext.Current.Response.AddHeader(过期,0);

As new in asp.net. In my asp.net application in membership in log off on click event using function ClearSession(), but problem arises after log off if i click back button on browser it is forwarding to the cached page. How to clear cache in browser so a user could not view its profile if he is not login

protected void ClearSession()
{
    FormsAuthentication.SignOut();
    Session.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ExpiresAbsolute = DateTime.UtcNow.AddDays(-1d);
    Response.Expires = -1500;
    Response.CacheControl = "no-Cache";
}

解决方案

I think you are almost there. You need more HTML headers to support all browsers. According to this article on SO these are the ones that work on all browsers:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

The full code for this is:

HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");

这篇关于如何清除浏览器缓存中,当用户使用C#在asp.net中注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆