开发者

Loop through Request object keys

This works to loop through all Form keys:

foreach (string s in Request.Form.Keys )        
        {       
            Response.Write(s.ToString() + ":" + Request.Form[s] + "<br>");      
        }

But, I want to loop through all Request keys:

foreach (string s in Request )      
        {       
            Response.Write(s.To开发者_JAVA技巧String() + ":" + Request[s] + "<br>");       
        }

Problem is request.keys is not a collection. But clearly the request object has children that I want to loop through. I'm pretty sure it's possible, I'm just using bad syntax.

thanks in advance!


use Request.Params:

foreach (string s in Request.Params.Keys )     
{       
    Response.Write(s.ToString() + ":" + Request.Params[s] + "<br>");       
}


Mark is correct this will work but it will return all the keys in cookies, the keys in form that is being sent , and the keys in the query strings and other key value pairs being sent. I suggest getting more specific. If you are receiving a Post object use

   Dictionary<string, string> _properties;
    foreach (string f in report.Form.Keys)
    {
        _properties.Add(f, report.Form[f]);
    }

and for a Get page use

    foreach(string s in report.QueryString.Keys)
    {
        _properties.Add(s,report.QueryString[s]);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜