[ASP.Net] a collection of keys and values.

Dictionary<TKey, TValue> Class

http://msdn.microsoft.com/zh-tw/library/xfhwa508(v=vs.100).aspx
http://msdn.microsoft.com/zh-tw/library/bb347013(v=vs.100).aspx
http://social.msdn.microsoft.com/Forums/en-US/926c2d0c-f7e3-48ff-ac86-28901ad18fc0/how-to-get-value-by-key-in-dictionary?forum=csharplanguage
http://stackoverflow.com/questions/12169443/get-dictionary-value-by-key
http://www.dotblogs.com.tw/puma/archive/2008/10/17/5711.aspx

廣告

7-Zip 最大壓縮比 command line

7z.exe a -t7z filename.7z filename -m0=LZMA:d128m:fb273 -mx=9 -ms=e

多個檔案,單一壓縮,批次寫法

echo off
set a=c:\program files\7-zip\7z.exe
for %%a in (*.log) do (
"%a%" a -t7z "%%~dpa%%~na.7z" "%%a" -m0=LZMA:d128m:fb273 -mx=9 -ms=e
)
Posted in Tools | 已加上的標籤

[ASP.Net] 跨網頁傳遞資料

http://www.dotblogs.com.tw/antony77/archive/2010/04/05/14417.aspx

使用 HttpWebRequest 來作
http://www.coolsun.idv.tw/modules/xhnewbb/viewtopic.php?topic_id=1273
http://coding.anyun.tw/2012/02/22/using-httpwebrequest-post-data/
http://www.dotblogs.com.tw/joysdw12/archive/2012/12/04/85380.aspx

//取得當前網址及路徑
string urlPath = "";
string[] segments = Request.Url.Segments;
for (int i = 0; i <= segments.Length - 2; i++)
{
    urlPath = urlPath + segments[i];
}

string bankUrl = string.Format("http://{0}:{1}{2}RedirectHandler.ashx", Request.Url.Host, Request.Url.Port, urlPath);
String parm = "BillerSeqNo=2014052361106509&Currency=NTD&Amount=1235500";

HttpTool http = new HttpTool();
NameValueCollection ackColl = http.SendRequest(bankUrl, parm);

if (ackColl == null)
{
    string alertScript = "處理失敗,請重新操作!<br />(ACK Null)";
    return;
}

string parm1 = ackColl["BillerSeqNo"];
string parm2 = ackColl["Currency"];

HttpTool.cs

using System;
using System.Web;
using System.Text;
using System.Net;
using System.IO;
using System.Collections.Specialized;

public class HttpTool
{
    public NameValueCollection SendRequest(string iTargetUrl, string iParam)
    {
        //此處的編碼要注意,是否會錯編 "&" 及 "=" 符號
        byte[] postData = Encoding.UTF8.GetBytes(iParam);
        HttpWebRequest request = HttpWebRequest.Create(iTargetUrl) as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Timeout = 10000;
        request.ContentLength = postData.Length;
        request.AllowAutoRedirect = false;  // 禁止重新導向網頁

        // 寫入 Post Body Message 資料流
        using (Stream st = request.GetRequestStream())
        {
            st.Write(postData, 0, postData.Length);
        }

        NameValueCollection qsColl = null;
        // 取得回應資料
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            if (response.StatusCode == HttpStatusCode.Found) // 判斷是否為 302
            {
                // 取得返回的Header中的Location參數,Location含有重新導向的網址資訊
                Uri redirectUrl = new Uri(response.Headers["Location"]);

                // 回傳全部參數的集合
                // Parse the query string variables into a NameValueCollection.
                qsColl = HttpUtility.ParseQueryString(redirectUrl.Query, Encoding.UTF8);
            }
        }
        return qsColl;
    }
}

RedirectHandler.ashx

using System;
using System.Web;
using System.Collections.Specialized;

public class RedirectHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string url = @"http://127.0.0.1/AppPayCB/PaymentResult.aspx";

        NameValueCollection pColl = context.Request.Params;
        string all = string.Format(@"{0}?BillerSeqNo={1}&Currency={2}", url, pColl["BillerSeqNo"], pColl["Currency"]);
        context.Response.Redirect(all);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}