简体   繁体   English

如何清除asp.net/javascript中的浏览器缓存?

[英]how to clear browser cache in asp.net/javascript?

In my program i need to handle with many images.I have to change images dynamically within the page. 在我的程序中,我需要处理很多图像。我必须在页面中动态更改图像。 after change the images i need to refresh the page by clear browser cache. 更改图像后,我需要通过清除浏览器缓存来刷新页面。

is there any method to clear cache or event for getting ctrl + f5 or ctrl + shift + del event in javascript or c# by a separate refresh button click. 是否有任何方法可以通过单击单独的刷新按钮来清除缓存或事件,从而在javascript或c#中获取ctrl + f5ctrl + shift + del事件。 Here I cannot use browser refresh button. 在这里,我无法使用浏览器刷新按钮。

No. You can set expiration time to zero, but this can be overridden in browser preferences. 不可以。您可以将到期时间设置为零,但是可以在浏览器首选项中将其覆盖。

If you really need that the browser don't cache image, generate a random number and place it in the url 如果您确实需要浏览器不要缓存图片,请生成一个随机数并将其放在网址中

you cannot clear browser cache.the only idea is declare a session variable in c# code in page load and set its value is 1 at the very first time 您无法清除浏览器缓存。唯一的想法是在页面加载时在c#代码中声明一个会话变量,并在第一次将其值设置为1

if (!IsPostBack)
            {
Session["refresh"]="1"
}

you will need to set session variable in image upload button event Session["refresh"]="1" then create a refresh button .in the button event do the following thats all.after completeing your upload,click on the refresh button.then it work as ctrl+f5 button.if you not set the session value 0 in refresh button event the last event is again takesplace.if you enter a value in database,the same task takesplace if you not set session variable 0. 您需要在图片上传按钮事件Session [“ refresh”] =“ 1”中设置会话变量,然后创建一个刷新按钮。在按钮事件中,请执行以下操作。完成上传后,单击刷新按钮。它用作ctrl + f5按钮。如果未在刷新按钮事件中将会话值设置为0,则再次发生最后一个事件。如果在数据库中输入值,则如果未将会话变量设置为0,则将执行相同的任务。

   if(Session["refresh"].ToString()=="1")
   {
      Response.Write("<script type='text/javascript'>locaton.reload()</script>");
      Session["refresh"]="0";
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM