asp.net Request.Form Request.para Request.Querystring 区别
2011-12-22 23:07 小sa 阅读(362) 评论(0) 编辑 收藏 举报- 用html 代码 post 或者 get 到default.aspx页面测试。
- Paras 和 Request[]获取的是 post 和 get的数据还有一些其他参数
- form获取的是post的数据
- Querystring获取的是get的数据 一般 url?var1=abc&var2=bcd 默认为get方法
html
<form action="default.aspx" method="post"> textbox 1<input type="text" id='Text1' name='nametxt1'/> textbox 2<input type="text" id="Text2" name='nametxt2' /> <input type="submit" value="submit" /> </form>
default.aspx
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Response.Write("<table border=1>"); Response.Write(string.Format("<tr><td colspan=2>method:{0}</td></tr>",Request.HttpMethod)); Response.Write("<tr><td colspan=2> Request.Params</td></tr>"); foreach (var s in Request.Params.AllKeys) { Response.Write("</tr>"); Response.Write(string.Format("<td><b>{0}</b></td><td>{1}</td>",s,Request.Params[s])); Response.Write("</tr>"); } Response.Write("<tr><td colspan=2>Request.Form</td></tr>"); foreach (var s in Request.Form.AllKeys) { Response.Write("</tr>"); Response.Write(string.Format("<td><b>{0}</b></td><td>{1}</td>", s, Request.Form[s])); Response.Write("</tr>"); } Response.Write("<tr><td colspan=2>Request.QueryString</td></tr>"); foreach (var s in Request.QueryString.AllKeys) { Response.Write("</tr>"); Response.Write(string.Format("<td><b>{0}</b></td><td>{1}</td>", s, Request.QueryString[s])); Response.Write("</tr>"); } Response.Write("<tr><td >Request</td><td>"); Response.Write(string.Format("nametxt1:{0} nametxt2 {1}", Request["nametxt1"], Request["nametxt2"])); Response.Write("</td></tr>"); Response.Write("</table>"); } }
3