s15199d s15199d -4 years ago 51
ASP.NET (C#) Question

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.ToString() + ":" + 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!

Answer Source

use Request.Params:

foreach (string s in Request.Params.Keys )     
    Response.Write(s.ToString() + ":" + Request.Params[s] + "<br>");       
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download