C# - How to list out variable names and values posted to ASPX page

后端 未结 8 2307
春和景丽
春和景丽 2021-02-13 10:11

I am dynamicaly generating a HTML form that is being submitted to a .aspx webpage. How do I determine in the resulting page what variable names were submitted and what the value

8条回答
  •  离开以前
    2021-02-13 10:32

    JohnFx's method works well. You can also include query string, server variable, and cookie data into the mix by using the Request.Params collection, as in:

    foreach(string key in Request.Params.Keys)
    {
      Response.Write(String.Format("{0}: {1}
    ", key, Request.Params[key])); }

    You need to be careful when using the Request.Params collection. If a QUERYSTRING variable and FORM variable both share key "Name" and have values "Val1" and "Val2", then the value of Request.Params["Name"] will be "Val1, Val2."

提交回复
热议问题