.Net 清除 IE7 IE8 IE9 快取 及 Cookie

嘗試了很多方式想要清除 Temporary Internet Files,但因為安全性無法列出所有檔案,所以無法清除!

其實只需利用 RunDll32.exe 即可達成刪除 快取 及 Cookie。

Temporary Internet Files

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

Cookies

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

History

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

Form Data

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

Passwords

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

Delete All

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

Delete All – “Also delete files and settings stored by add-ons”

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

  2012-06-04      ez      .NET
Javascript 也能有 Multi-Thread 利用 Conurrent Thread Library

以往常常遇到 Javascript 執行較長時間就會出現 "終止Javascript警訊" 或 "瀏覽器當掉",此時就可以利用 Conurrent Thread Library,就可以達到 Multi-Thread 效果,就不會當掉了。

檔案下載:Concurrent.Thread-full-20090713

相關說明:http://sourceforge.net/apps/mediawiki/jsthread/

範例:

<script src="Concurrent.Thread-full-20090713.js" language="javascript"></script>
<script language="javascript" type="text/javascript">
Concurrent.Thread.create(function(){
  var i = 0;
  while(true) document.body.innerHTML += (i++) + " ";
});
</script>

  2012-05-23      ez      JavaScript
.Net 網頁信箱 防止垃圾郵件

網頁中常常會出現明碼的信箱位址,時常會被機器人爬取,做為廣告發送目標。

本篇我利用 .Net 產生 JavaScript,防止機器人直接抓取原始碼中的電子信箱位址。

using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Test
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(MailToJS("[email protected]"));
        }

        /// <summary>
        /// 產生指定範圍的亂數
        /// </summary>
        /// <param name="Min"></param>
        /// <param name="Max"></param>
        /// <returns></returns>
        public int RandomNext(int Min, int Max)
        {
            RNGCryptoServiceProvider rngp = new RNGCryptoServiceProvider();
            byte[] rb = new byte[4];

            rngp.GetBytes(rb);
            int value = BitConverter.ToInt32(rb, 0);
            value = (value % (Max - Min + 1));
            if (value < 0) value = -value;
            value += Min;
            return value;
        }

        /// <summary>
        /// 將信箱轉為JS
        /// </summary>
        /// <param name="Mail"></param>
        /// <returns></returns>
        protected string MailToJS(string Mail)
        {
            List<string> CList = new List<string>();
            for (int i = 32; i <= 64; i++) CList.Add(Convert.ToChar(i).ToString());
            for (int i = 91; i <= 126; i++) CList.Add(Convert.ToChar(i).ToString());
            List<string> NList = new List<string>();
            while (CList.Count > 0)
            {
                int R = RandomNext(0, CList.Count - 1);
                NList.Add(CList[R]);
                CList.RemoveAt(R);
            }

            List<int> EList = new List<int>();
            Mail = Mail.ToLower();
            Mail = "<a href=\"mailto:" + Mail + "\" hidefocus=\"true\">" + Mail + "</a>";
            foreach (char c in Mail) EList.Add(NList.IndexOf(c.ToString()));

            for (int i = 0; i < NList.Count; i++)
            {
                if (NList[i] == "'")
                    NList[i] = "'" + NList[i].Replace("'", "\\'") + "'";
                else if (NList[i] == "\\")
                    NList[i] = "'" + NList[i].Replace("\\", "\\\\") + "'";
                else
                    NList[i] = "'" + NList[i] + "'";
            }

            StringBuilder SB = new StringBuilder();
            SB.AppendLine("<script type=\"text/javascript\">");
            SB.AppendLine("<!--");
            SB.AppendLine("\t(function(){");
            SB.AppendLine("\t\tvar ek = [" + String.Join(",", NList.ToArray()) + "];");
            SB.AppendLine("\t\tvar en = [" + String.Join(",", EList.ToArray()) + "];");
            SB.AppendLine("\t\tvar ds = \"\";");
            SB.AppendLine("\t\tfor(var i in en) ds += ek[en[i]];");
            SB.AppendLine("\t\tdocument.write(ds);");
            SB.AppendLine("\t})();");
            SB.AppendLine("// -->");
            SB.AppendLine("</script>");

            return SB.ToString();
        }
    }
}

  2012-06-04      ez      .NET
Ubuntu 安裝 Proxy Server (squid)

安裝 squid 指令:

apt-get install squid

安裝完成後,編輯 /etc/squid3/squid.conf:

vi /etc/squid3/squid.conf

編輯 http_port 預設為 3128,可以改為想設定的 Proxy Port:


  2012-06-04      ez      Linux
.Net 匯出到 Excel 利用 NPOI 指定欄位儲存格格式

利用 NPOI 指定欄位儲存格格式:

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("工作表名稱");
HSSFRow Row = (HSSFRow)sheet.CreateRow(0);
//欄位為數值 注意不可為字串
Row.CreateCell(0).SetCellValue(Convert.ToDouble("123"));

HSSFCellStyle cs = (HSSFCellStyle)workbook.CreateCellStyle();
//Format格式為數字
cs.DataFormat = HSSFDataFormat.GetBuiltinFormat("0");
//Format格式為百分比小數兩位
cs.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
Row.GetCell(0).CellStyle = cs;

  2012-05-10      ez      .NET
.Net 匯出到 Excel 利用 NPOI 公式指令

利用 NPOI 公式指令:

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("工作表名稱");
HSSFRow Row = (HSSFRow)sheet.CreateRow(0);
Row.CreateCell(0).CellFormula = "SUM(A1:B1)";
Row.CreateCell(1).CellFormula = "A1-B1";
//更新有公式的欄位
sheet.ForceFormulaRecalculation = true;

  2012-05-10      ez      .NET