• asp.net notes


    1. cache's expire problem
       string sendTimeKey = "abc_sendtime";
              //DateTime dtLast = (DateTime)cache[sendTimeKey];
              if (Cache[sendTimeKey] == null)
              {
                  Cache.Insert(sendTimeKey, 1, null, DateTime.MaxValue, TimeSpan.FromSeconds(3));//, CacheItemPriority.Normal, null);
                  Response.Write("no cache, added");
              }
              else
              {
                  Cache[sendTimeKey] = (int)Cache[sendTimeKey] + 1;// .Insert(sendTimeKey, DateTime.Now, null, DateTime.MaxValue, TimeSpan.FromSeconds(50));
                  //if (total >= 100)
                  {
                      Response.Write("has cache");
                  }
              }
              Response.Write(Cache[sendTimeKey].ToString());
      上面的代码会造成一旦进入else语句之后,cache将不会在3秒内过期,除非应用重启,原因是直接cache[key] = value,并未设置cache的过期时间,因此将永不过期,因此如果要让cache在sliding expiration,则应该在else中也使用cache.insert()指定过期时间.
      当然,如果不使用slidingExpiration,而是使用绝对时间过期,则只需要在第4个参数不用dateTime.MaxValue,设置一个相应的时间即可,而最后一个参数则应该为TimeSpan.Zero.
    2.  *.axd文件在http://ip/或机器名方式下访问不了,而在vs2k8的debug模式下可以看到,最后发现是在IIS中需要将application pool设置为classic .net pool,而不是defaultpool即可.
    3. dropdownlist中的value如果有相同的,则可能在选择后面的ListItem时,selectedIndex仍然是指向前面的;另外就是应该在初始化dropdownlist时判断Page.IsPostBack.
    4.  关于使用response.Redirect或response.WriteFile时的一点解决方案
      使用response.Redirect或response.writeFile下载文件时,如果还要对当前页面中的server control进行处理,
      则在处理完所有页面逻辑代码之后,使用js代码重定向到下载文件,否则与UI相关的代码将不会执行.
      ex:
      btnDown_click()
      {
      lbAll.Visible = true;  // 显示另一个linkbutton
              string strStartUpScript = "<script language='javascript' type='text/javascript'>window.location.href='newdown3.aspx?fn=" + Server.UrlEncode(fileName) + "';</script>";
              ClientScript.RegisterStartupScript(Page.GetType(), "PopupScript", strStartUpScript);
      }


  • 相关阅读:
    C#中提供的精准测试程序运行时间的类Stopwatch
    [转]SQLite数据库扫盲
    [转]c# 使用ChartDirector绘图的一些个人体会
    [转]SQLite内存数据库
    SQL Server 各种查询语句执行返回结果
    [转]浅谈 BigInteger
    [转]SQLite数据库连接方式
    ASP.NET 3.5 开发大全DOC版
    好像昨天不见了100块钱。
    热烈庆祝本人昨天终于申请得了google ad
  • 原文地址:https://www.cnblogs.com/margiex/p/1045783.html
Copyright © 2020-2023  润新知