zoukankan      html  css  js  c++  java
  • ASP.Net中让网页“立即过时”

      让网页“立即过时”有时候是一个很有用的功能,比如防止用户使用后退来破坏程序逻辑;程序主动刷新某个页面等等。在ASP中最有效的方法是:
    Response.CacheControl = "no-cache"
    就这么一句足矣,Response.Expires=-1之类的其实都不需要,也不符合我们的要求。
      但到了ASP.Net的时代,当我还糊里糊涂地使用这条语句时,发现MSDN中对Response的这个字段的说明是:
    Sets the Cache-Control HTTP header to Public or Private. 
    [C#] 
    public string CacheControl {get; set;} Property Value 
    "Public" or "Private". 
    Exceptions 
    ArgumentException: CacheControl is an invalid cache control value (not Private or Public). 
    怎么只允许赋"public"和"private"两种值了?但是一实验方知是MS在唬人,只要是合法的cache-control的HTTP head值都可以接受,当然包括no-cache了。
      而且经实践,这种方法的功能仍然与ASP中是一样的。当然,似乎.Net官方推荐这种方法:
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
    这个效果和前者完全一致。
      最后,有一点要注意,似乎只有IE的结果是对的,Firefox不买这个帐……
  • 相关阅读:
    CodeForces 734F Anton and School
    CodeForces 733F Drivers Dissatisfaction
    CodeForces 733C Epidemic in Monstropolis
    ZOJ 3498 Javabeans
    ZOJ 3497 Mistwald
    ZOJ 3495 Lego Bricks
    CodeForces 732F Tourist Reform
    CodeForces 732E Sockets
    CodeForces 731E Funny Game
    CodeForces 731D 80-th Level Archeology
  • 原文地址:https://www.cnblogs.com/wonderow/p/242376.html
Copyright © 2011-2022 走看看