Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 循环通过请求对象键_C#_Asp.net - Fatal编程技术网

C# 循环通过请求对象键

C# 循环通过请求对象键,c#,asp.net,C#,Asp.net,这可以循环使用所有表单键: foreach (string s in Request.Form.Keys ) { Response.Write(s.ToString() + ":" + Request.Form[s] + "<br>"); } foreach(Request.Form.Keys中的字符串s) { Response.Write(s.ToString()+“:

这可以循环使用所有表单键:

foreach (string s in Request.Form.Keys )        
        {       
            Response.Write(s.ToString() + ":" + Request.Form[s] + "<br>");      
        }
foreach(Request.Form.Keys中的字符串s)
{       
Response.Write(s.ToString()+“:“+Request.Form[s]+”
”; }
但是,我想循环遍历所有请求密钥:

foreach (string s in Request )      
        {       
            Response.Write(s.ToString() + ":" + Request[s] + "<br>");       
        }
foreach(请求中的字符串s)
{       
Response.Write(s.ToString()+”:“+Request[s]+”
”; }
问题是request.keys不是集合。但是很明显,请求对象有我想要循环的子对象。我很确定这是可能的,我只是使用了错误的语法

提前谢谢

使用:

foreach(Request.Params.Keys中的字符串s)
{       
Response.Write(s.ToString()+”:“+Request.Params[s]+”
”; }
标记正确这将起作用,但它将返回Cookie中的所有键、正在发送的表单中的键以及正在发送的查询字符串和其他键值对中的键。我建议更具体一些。如果您正在接收Post对象,请使用

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

意识到这是相当古老的,但你的意思是
请求
不是
报告
   Dictionary<string, string> _properties;
    foreach (string f in report.Form.Keys)
    {
        _properties.Add(f, report.Form[f]);
    }
    foreach(string s in report.QueryString.Keys)
    {
        _properties.Add(s,report.QueryString[s]);
    }