먹는게 남는거다!

'949'에 해당되는 글 1건

  1. ASP.NET Request QueryString encoding

ASP.NET Request QueryString encoding

C#, ASP.NET
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
private System.Collections.Generic.Dictionary<stringstring> requestDic;
 
protected void Page_Load(object sender, EventArgs e)
{
    ParseRequestQueryStringData(System.Text.Encoding.GetEncoding(949));
 
    string t = GetRequestQueryString("strErrMsg");
    lbMessage.Text = t;
}
 
private void ParseRequestQueryStringData(System.Text.Encoding encoding)
{
    string url = HttpUtility.UrlDecode(Request.RawUrl, encoding);
    int s = url.IndexOf('?'0);
    if (s < 0)
    {
        return;
    }
 
    requestDic = new System.Collections.Generic.Dictionary<stringstring>();
    string requestData = "&" + url.Substring(s + 1+ "&";
 
    int pos = requestData.IndexOf('&'0);
    int pos2 = 0;
 
    string paramName;
    string paramValue;
 
    while (pos >= 0 && pos2 >= 0)
    {
        pos2 = requestData.IndexOf('=', pos);
 
        if (pos2 > 0)
        {
            paramName = requestData.Substring(pos + 1, pos2 - pos - 1);
 
            pos = requestData.IndexOf('&', pos2);
 
            if (pos > 0)
            {
                paramValue = requestData.Substring(pos2 + 1, pos - pos2 - 1);
                requestDic.Add(paramName, paramValue);
            }
        }
    }
}
 
private string GetRequestQueryString(string paramName)
{
    try
    {
        return requestDic[paramName];
    }
    catch (System.Collections.Generic.KeyNotFoundException keyEx)
    {
        return null;
    }
}
cs