【发布时间】:2010-11-05 05:38:23
【问题描述】:
检索传递给 .aspx (VB) 页面的 GET(在 URL 中)变量的最简单/标准方法是什么?
【问题讨论】:
-
这是一个来自 SO 的示例,用于循环遍历 GET 回发值。 http://stackoverflow.com/questions/562943/looping-through-a-request-querystring-in-vb-net
检索传递给 .aspx (VB) 页面的 GET(在 URL 中)变量的最简单/标准方法是什么?
【问题讨论】:
您可以使用以下内容:
示例网址:http://www.whatever.com?hello=goodbye&goodbye=hello
string value = Request.QueryString("hello");
价值将是再见
或
foreach(string key in Request.QueryString)
{
Response.write(Request.QueryString(key))
}
【讨论】:
Request.QueryString["hello"] 不起作用。 Request.QueryString("hello") 会。
如果你有路径:
www.stackoverEvan.com/question/directory-lookup.asp?name=Evan&age=16
如果你这样做:
Hi , <%= Request.QueryString("name") %>.
Your age is <%= Request.QueryString("age") %>.
输出:
欢迎,埃文。你的年龄是 16 岁
但是当您在 VB 中指定它时,最佳方式如下:
路径:
http://localhost/script/directory/NAMES.ASP?Q=Evan&Q=Bhops
代码:
--- Names.asp ---
<%
For Each item In Request.QueryString("Q")
Response.Write Request.QueryString("Q")(item) & "<BR>"
Next
%>
输出:
埃文
博普斯
【讨论】:
查看 Request.QueryString 集合
【讨论】: